Code Monkey home page Code Monkey logo

runkit-farm-worker's Introduction

Runkit-farm-worker

https://orchestrate.io contact us : [email protected] var db = require('orchestrate')(process.env.ORCHESTRATE_KEY)

exports.tonicEndpoint = async function(request, response) { await db.newPatchBuilder("counts", process.env.TONIC_MOUNT_PATH) .upsert(true) .init("count", 0) .inc("count") .apply()

var hits = await db.get("counts", process.env.TONIC_MOUNT_PATH)

response.end(hits.body.count.toString())

}

*We've set our Orchestrate API key in our environment variables, which we use to initialize the db at the start. Then, on every request, we simply increment the count. Finally, we retrieve the current count and return it.

It's important to do the increment this way, so that concurrent updates aren't lost. We then read back out the current value, which may have been updated by someone else already, but that doesn't much matter.

The count is stored on a document with an ID matching the "TONIC_MOUNT_PATH" environment variable, which is the URL of this document.

*ll documents on RunKit are public, you can make them searchable by publishing. all of npm's 1,000,000+ packages are already pre-installed, just require() them use arrow functions, classes, template strings, and most of ES6. See everything we support here. await any promise instead of using callbacks (example) store secrets in environment variables export an endpoint function to turn any notebook into an API (endpoint docs)

runkit-farm-worker's People

Contributors

x-oss-byte avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.