Skip to content

Instantly share code, notes, and snippets.

@hoetmaaiers
Last active December 5, 2019 08:22
Show Gist options
  • Save hoetmaaiers/8fcaba08f4b11353bb7d3acb39285f2e to your computer and use it in GitHub Desktop.
Save hoetmaaiers/8fcaba08f4b11353bb7d3acb39285f2e to your computer and use it in GitHub Desktop.
technical question - async caculation scenario

The context is a long running server side calculation. Because of this long running necessity, we can not use the default request/response, but need to handle it asynchronously.

We have 3 api endpoints available to implement this asynchronous result calculation.

  1. Uplaod the data to process
  2. Track the caculation process
  3. Return the calculation result

Upload

# request:
http POST /upload data=fleet-2019.xml

# response:
{ 
  data: {
    progressId: number
  }, 
  meta: {
    type: 'upload'
  }
}

Wait for progress

# request:
http GET /upload-progress progressId=number

# response:
{ 
  data: {
    status: 'IN_PROGRESS'
  }, 
  meta: {
    type: 'upload-progress'
  }
}

Go fetch upload result

# request:
http GET /upload-result progressId=number

# response:
{ 
  data: [ 
    # upload result data
    ...
  ], 
  meta: {
    type: 'upload-progress'
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment