Skip to content

Job Function Operation

The Job Function operation executes JavaScript or TypeScript code asynchronously via the Function Service. It is typically used for tasks that do not require an immediate response, long-running operations that may exceed synchronous request timeouts, and background processes triggered by events or schedules.

Unlike synchronous functions, which return results directly, a Job Function returns an execution ID that can be used to track the status of the task.

For more details on writing functions, refer to the Function Service documentation.

Configuration Example

typescript
createExecutor({
  name: "job-function-executor",
  description: "Execute asynchronous job function",
  trigger: scheduleTrigger({ cron: "0 0 * * *" }),
  operation: {
    kind: "jobFunction",
    body: async () => {
      // Long-running task logic
      const taskId = `task-${Date.now()}`;
      const timestamp = new Date().toISOString();
      // Background processing logic here
    },
  },
});

Properties

Executor Properties

PropertyTypeRequiredDescription
namestringYesThe name of the executor. The name field has the validation rule ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$, and it does not allow capital letters
descriptionstringNoThe description of the executor
triggerobjectYesThe type of trigger (e.g., scheduleTrigger, eventTrigger, webhookTrigger)

Job Function Operation Properties

PropertyTypeRequiredDescription
kindstringYesMust be "jobFunction" for job function operations
bodyfunctionYesAn async function containing the long-running task logic

Executor Properties

PropertyTypeRequiredDescription
namestringYesThe name of the executor. The name field has the validation rule ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$, and it does not allow capital letters
workspace_idstringYesThe ID of the workspace that the executor namespace belongs to
descriptionstringNoThe description of the executor
triggerobjectYesThe type of trigger (webhook, event, or schedule)

Job Function Operation Properties

PropertyTypeSupports ScriptingRequiredDescription
namestring-YesThe name of the job function
scriptstring-YesThe JavaScript/TypeScript code to execute
invokerobject-NoThe invoker of the operation
variablesstringJavaScript / CELNoThe variables to pass to the job function. Can access trigger-specific data via args object

Executor Properties

PropertyTypeRequiredDescription
NamestringYesThe name of the executor. The name field has the validation rule ^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$, and it does not allow capital letters
DescriptionstringNoThe description of the executor
TriggerobjectYesThe type of trigger (e.g., #TriggerIncomingWebhook, #TriggerEvent, #TriggerSchedule)

TargetJobFunction Properties

PropertyTypeSupports ScriptingRequiredDescription
Namestring-YesThe name of the job function
ScriptPathstring-YesThe path to the JavaScript/TypeScript script file
Invokerobject-NoThe invoker of the operation
VariablesstringJavaScript / CELNoThe variables to pass to the job function. Can access trigger-specific data via args object

Use Cases

Job functions are ideal for:

  • Long-running operations: Tasks that may take several minutes or hours to complete
  • Background processing: Operations that don't require immediate response
  • Batch processing: Processing large datasets or multiple records
  • External API integrations: Calling external services that may have high latency
  • File processing: Uploading, downloading, or transforming files
  • Email notifications: Sending emails or other notifications
  • Data synchronization: Syncing data between systems