Run Scheduled Jobs

Automate cleanup routines, reports, and data syncing with Spala tasks.

Run Scheduled Jobs

Use tasks for backend work that should run without a user request: cleanup routines, recurring reports, imports, sync jobs, and long-running operations.

Steps

Create a task

Go to Tasks and click New Task. Give it a clear name, such as cleanup-expired-sessions or sync-stripe-customers.

Choose how it runs

Set a repeat frequency and unit, such as every 15 minutes, every 1 hour, or every 1 day. Leave the schedule empty when you want a manual task that only runs when started directly.

Build the task function

Add steps for the work the task should do. For a cleanup task, query stale records, delete or update them, then log the result.

Tune execution

Use Run in Background for longer work. Set timeout and memory limits so expensive jobs fail predictably instead of silently consuming resources.

Example Cleanup Task

1. Set Variable - Name: cutoff, Value: '' | now | addHours(-24) | toISO
2. Database Delete - Table: sessions, Where: { expires_at: { $lt: vars.cutoff } }, Returning: id, Assign To: deleted
3. Log - Message: 'Cleaned up ' + (vars.deleted | length) + ' expired sessions'

When To Use Manual Tasks

Manual tasks are useful for admin jobs that should not run on a timer:

- Backfill missing data after an import
- Recalculate analytics
- Re-send a batch of notifications
- Run a one-off cleanup before publish

Use background execution for long jobs

Tasks that process many records or call external APIs should run in the background. Monitor them from Background Tasks to see status, logs, result data, retries, and failures.

Scheduled Tasks
/tasks/scheduled-tasks
Configure repeat frequency, manual runs, and resource limits
Background Tasks
/tasks/background-tasks
Monitor queued, running, completed, and failed work
Send Emails
/guides/send-emails
Send reports and alerts from tasks