Introduction
Background tasks are scheduled workflows that run in the background, independently of any API request or other logic. They’re ideal for recurring operations like data cleanup, notifications, or re-engagement campaigns. Unlike APIs and custom functions, background tasks do not accept inputs or return a response. They are only used to run logic on a schedule.Anatomy
Every XanoScript background task follows a predictable structure. Here’s a quick visual overview of its main building blocks — from declaration at the top to settings at the bottom.You can find more detail about each section by continuing below.
XanoScript
Declaration
Every Background Task starts with a declarative header that specifies its type, name, and HTTP verb.XanoScript
Element | Required | Description |
---|---|---|
task | ✅ | Declares an Background Task primitive. |
task_name | ✅ | The unique name for the task (e.g., reengage_users ). |
description | no | Optional human-readable description of the task. |
active | no | Whether the task is active. |
datasource | no | Specifies the datasource to use for this Background Task. |
Section 1: Stack
Thestack
block contains the actual logic that will be executed when the Background Task is running.
Hover over this image to see the XanoScript version
Review all available functions and their XanoScript in the function reference
Section 2: Schedule
Theschedule
block contains the schedule in which the Background Task will run on.
You may know this as the ‘Timing’ section in the visual builder.
Hover over this image to see the XanoScript version
The schedule begins with an
events
array, which contains one or more objects to represent a schedule entry. Each schedule entry contains a starts_on
date/time in YYYY-MM-DD HH:MM:SS+TZ format, a freq
in seconds which defines the interval between runs, and can also contain an ends_on
date/time in YYYY-MM-DD HH:MM:SS+TZ format. If ends_on
is not provided, the task will run indefinitely.If you’re not familiar with background tasks in Xano, you can learn more about them here.Section 3: Settings
There are several optional settings that can be configured for a Background Task. These settings are defined at the root level of the Background Task block, after the definition, stack, and schedule blocks. They affect how the task behaves.Setting | Type | Required | Description |
---|---|---|---|
description | string | no | A human-readable description of the Background Task. Appears in the builder and documentation. |
tags | array[string] | no | A list of tags used to categorize and organize the Background Task in your workspace. |
history | object | no | Configures version inheritance and history behavior. {inherit: true} allows this Background Task to inherit history settings from the workspace. |
Detailed Example
Below, you’ll see a complete example of a typical signup Background Task endpoint.XanoScript
What’s Next
Now that you understand how to define Background Tasks in XanoScript, here are a few great next steps:Explore the function reference
Learn about the built-in functions available in the stack to start writing more complex logic.
Try it out in VS Code
Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.
Learn about Triggers
They work just like your APIs and custom functions, but they run only when certain other events happen, such as new records in a table.