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

Context and Task

Data Context is an object injected into logic functions at runtime, which containes some key components:

  • Task and execution-related information
  • Trigger payload

Availability

  • ✓ Generic logic
  • ✓ Aggregator logic

Context

Type:

  • GenericContext (generic logic)
  • AggregatorContext (aggregator logic)

When a logic gets executed, a data context object ctx will be available in both run and handleError functions:

export async function run(ctx) {
// ctx is the data context
}

export async function handleError(ctx, error) {
// the same context as well as error
}

Railway Error

Type: RailwayError

RailwayError is a object extended from the standard Error class, which will be passed to handleError() upon an error occurred:

export async function handleError(ctx, error) {
// ...
const errorMessage = error.message; // error message
const errorLogicId = error.logicPermanentIdentity; // the PID of the logic that have error occurred
const errorLogicRevision = error.logicRevision; // the revision of the logic that have error occurred
}

See Tips on Error Handling for details on logic error handling.

Task

Type: Task

export async function run(ctx) {
const task = ctx.task;
}

A task is an execution of this particular data process invoked by a trigger. The task object is lazy-loaded and would include all related metadata to the logic context:

MemberTypeDescription
taskKeyTaskKey, which is { taskId: string, executionId: string }Task ID and execution ID
taskId (deprecated)taskId, which is { id: string, executionId: string }Task ID and execution ID
startTimestampDateTask start datetime
startAt (deprecated)DateTask start datetime
dataProcessVersionedIdentityContextData process permanent ID
currentLogic?VersionedIdentityContextCurrent logic permanent ID
executedLogicsArray<VersionedIdentityContext>An array of identity of executed logic

Versioned Identity Context

Represents the identity of a logic or a data process:

MemberTypeDescription
namestringName
permanentIdentitystringPermanent identity string (PID)
revisionnumberRevision number

Example

const taskId = ctx.task.taskKey.taskId;
const executionId = ctx.task.taskKey.executionId;

// you can still use the deprecated interfaces:
// const taskId = ctx.task.taskId.id;
// const executionId = ctx.task.taskId.executionId;

const dpPid = ctx.task.dataProcess.permanentIdentity;
const logicPid = ctx.task.currentLogic.permanentIdentity;