Synchronous and asynchronous Triggered Task execution
The sync/async behavior of a Triggered Task is determined by pipeline design, not by the URL endpoint used to invoke the task.
When you invoke a Triggered Task, two separate but related processes occur. The first is the HTTP response behavior — whether the HTTP call waits for the pipeline to finish before returning a response (synchronous), or returns a response almost immediately while pipeline execution continues in the background (asynchronous). The second is the pipeline's data processing, which moves and transforms data through Snaps on the Snaplex and runs to completion independently of the HTTP response timing.
The sync/async distinction in a Triggered Task refers to the HTTP response, not the underlying data payload processing. This behavior is determined by pipeline design: whether the pipeline includes a Snap with an unterminated output. Both the Cloud URL and the Snaplex/Alternate URL on the Task Details page can be used to invoke the task; the pipeline design determines whether the resulting HTTP response is synchronous or asynchronous.
By default, when a pipeline runs to completion without an unterminated output Snap, the task call is synchronous: the HTTP connection waits for the pipeline to finish and returns a status code on completion. To achieve asynchronous behavior, add a Snap with an unterminated output to the pipeline. That Snap's output is streamed back as the HTTP response payload as soon as it is produced, before the full pipeline completes.
Synchronous execution
The Task responds with an HTTP response status code on completion.
For example, in the following pipeline:
When you trigger the task created from this pipeline, for example from a browser, you receive an HTTP response status code on completion, such as:
{ http_status_code: 200 }
The request waits until the pipeline execution completes before displaying this message.
Asynchronous execution
If the pipeline has a single, unterminated Snap providing output, the output from that Snap is provided as the response to the request. This behavior lets you make the pipeline asynchronous, in that the response is written back to the user. To make the pipeline asynchronous, add a Snap with an unterminated output, as shown in the following example:
Now when you trigger the task created from this pipeline, the output from the response generator Snap is provided almost as soon as the pipeline execution starts.
In this case, a JSON Generator responds with the message:
{ msg: "Started Ok", http_status_code: 200 }
The net effect is that the pipeline execution behaves asynchronously.
Customizing the HTTP response status code
You can view the task status in the browser, the same as on the output view of the pipeline. In this pipeline, the execution status is routed to the error view, which is redirected to reflect in the browser using the Binary Header Properties of the JSON Formatter Snap.
The workaround of using Binary Header properties is mainly useful when you want to view the exact execution status of the Triggered Task, which might not be consistent with the status code otherwise reflected on the browser.
The status code (405) as retrieved from the pipeline is mapped to the response:
The JSON Formatter Snap passes the actual status code to the browser via the Binary Header Properties: