Returning progress and intermediate results

It can be useful to return intermediate results from a background process.

This is identical to the callback complete action, except that it is called "progress".

In the caller, add a progress next step.

{
"name": "anchor",
"script": "stepTypeCallback",
"next": {
  "prepare": "call",
  "complete": "complete",
  "progress": "doSomethingWithProgress",
  "*": false
}
}

Provide a suitable step to do something with the "progress" response.

In the asynchronous script, use something like this.

{
"name": "sendProgress",
"script": "stepTypeCallback",
"config": {
  "callbackAction": "progress",
  "callbackData": {
    // Progress data
  }
},
"next": false
}

The response can contain anything. If the callbackToken attribute is not set to the token, you must set it explicitly in the config.callbackToken property.

In the calling script, add progress to the next clause to pick up progress.

Response store

If you want to return the response from the most recent callback (e.g. a progress update), you can set the callbackStoreResponse option to true in the anchor step.

{
"name": "anchor",
"script": "stepTypeCallback",
"config": {
  "callbackStoreResponse": true
},
"next": {
  "prepare": "call",
  "complete": "complete",
  "*": false
}
}

This stores each response passed to the callback, and returns it on a query action. The query result is a merge where later values override earlier ones. The order of merging is:

  • callbackData config property (stored during create)
  • response callbackData (stored on run previous to this)

There is no next branch for progress (the response is stored automatically) or query (which will look at the stored response).

The response store is cleaned up automatically. It will localise files in fileInfo structures, ensuring temporary files are persisted in long-running processes.

The response store is particular useful where the same process worker can support multiple active callbacks at the same time (for example, a control process in a module), when you will need to provide per-callback storage to record progress.