Function: job()
job(
fn,config):Job
Creates a Job definition.
Jobs are background tasks that persist across server restarts, can be
retried on failure, delayed, and scheduled with cron. Pass the worker
function as the first argument and configure the executor and schedule
in config.
See Recurring Jobs.
Parameters
fn
Reference<AnyFunction>
The async function that performs the job's work. It receives the submitted args and a context containing the declared entities.
config
Required executor and optional schedule, entities,
and performExecutorOptions.
entities?
string[]
Entities the worker operates on. Wasp injects a Prisma delegate for
each one into the worker's context.entities.
executor
"PgBoss"
Executor backing this job.
performExecutorOptions?
Executor-specific default options used when submitting the job.
These options are passed through to the executor and can be overridden when submitting the job or by Schedule.executorOptions for scheduled runs. For example, with PgBoss this can set retry limits, expiration, or priority.
Default
{}
schedule?
Cron schedule that runs the job automatically.
Returns
Example
import { job } from '@wasp.sh/spec'
import { foo } from './src/jobs/bar' with { type: 'ref' }
job(foo, {
executor: 'PgBoss',
entities: ['Task'],
schedule: { cron: '0 * * * *' },
})