Giter Club home page Giter Club logo

longrun's Introduction

Long run

Handling long run REST call.

Goals

Handling long REST call, without blocking, without polling.

  • Distant RPC with HTTP
  • RPC can be "fire and forget" or streaming responses
  • RPC can be canceled
  • Server is async, client can be sync
  • Golang, python, javascript languages

Flow

Polling

You can be old fashioned, with long polling. It works with curl.

    | POST /{object}/      |
    | JSON body            |
rpc |--------------------->|
    |  rpc_id, Location    | fast response with a unique ID with a 303 status
    |<---------------------|
    | GET /{object}/{id}   | ask for events
    | Last-Event-Id header | since 0
    |--------------------->|
    | [events]             | 
    |<---------------------|
    | GET /{object}/{id}   | ask for events
    | Last-Event-Id header | since last id
    |--------------------->|
    | [events]             | 
    ...

last-event-id can be a header, or a query argument.

The communication is async, the server doesn't wait client. Client can only do the first step. If client is slow, and server fast, the response will contain more than one events.

Server Sent Event

    | POST /{object}/      |
    | JSON body            |
rpc |--------------------->|
    |  rpc_id, Location    | fast response with a unique ID with a 303 status
    |<---------------------|
    | GET /{object}/{id}   | ask for events
    |--------------------->|
    | event                |
    |<---------------------|
    | event                |
    |<---------------------|
    | event                |
    |<---------------------|
    | event                |
    |<---------------------|
    ...

SSE is a very simple streaming workflow : with a GET request, the response is a streamed text, using lines (with \n), and blank line for ending an event message.

Client ask for a run, with a POST http request, the arguments are a map, JSON serialized, in the body of the request. The JSON response return the run id. The default response use a 201 Created status. If the request has the header accept: text/event-stream, the response with a 303 See other with a Location: to the run endpoint.

Methods

POST Ask something, it creates a run.

GET subscribe to run events. Multiple connections can watch a single run.

HEAD ask if a run exists.

DELETE cancel a run.

Events

Events describe change in states.

Events are ordered, and typed (its state).

States are:

  • queued (implicit first state)
  • running (more than one running state is possible)
  • canceled
  • error
  • success

Attributes:

  • id: rank
  • value
  • state

Licence

CC BY-SA 4.0

longrun's People

Contributors

athoune avatar gawel avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  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.