Skip to main content
Version: LOC v0.9 (legacy)

Result Agent

import { ResultAgent } from "@fstnetwork/loc-logic-sdk";

Finalise a JSON object as the task result data. If the trigger is synchronized API route or message queue, it will be returned to the trigger, otherwise stored in LOC to be retrieved later.

Task results woulbe be embedded in an execution result from a trigger unless the trigger's encapsulation is turned off. Be noted that single data process execution also only returns task results.

Availability

  • ✗ Generic logic
  • ✓ Aggregator logic

Finalise Result

ResultAgent.finalize(value: object)

value has to be a JSON object (a JavaScript object without methods).

tip

The result agent can be used in both run and handleError functions and does not need await.

See the tutorial for tips on using result agent for error handling.

Example

ResultAgent.finalize({
status: "ok",
taskId: ctx.task.taskKey,
data: {
name: "Arthur Dent",
age: 42,
},
});

Be noted that status: "ok" is not the HTTP response code, but an user-defined field that indicates the task has been executed without issues.

The finalised data (task result) will be

{
"status": "ok",
"taskId": {
"executionId": "...",
"id": "..."
},
"data": {
"name": "Arthur Dent",
"age": 42
}
}
Seperate multiple task results in the same execution

If you are planning to execute multiple data processes from the same trigger, be adviced not to use shared task result field names (for example, status and data), for the result of one data process would be overwritten by another.

You can wrap results with different topmost keys:

aggregator 1
ResultAgent.finalize({
result_data_process_a: {
status: "ok",
taskId: ctx.task.taskKey,
data: {
name: "Arthur Dent",
age: 42,
},
},
});
aggregator 2
ResultAgent.finalize({
result_data_process_b: {
status: "ok",
taskId: ctx.task.taskKey,
data: {
name: "Ford Perfect",
age: 200,
},
},
});

The returned task results in the execution result would thus be

{
"result_data_process_a": {
"status": "ok",
"taskId": {
"executionId": "...",
"id": "..."
},
"data": {
"name": "Arthur Dent",
"age": 42
}
},
"result_data_process_b": {
"status": "ok",
"taskId": {
"executionId": "...",
"id": "..."
},
"data": {
"name": "Ford Perfect",
"age": 200
}
}
}