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.
Use reference imports when passing values from your app into the Wasp spec. If a direct import is not practical, use ref as a fallback.
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.
This works like entity access in queries and actions. See Using Entities in Queries.
executorโ
"PgBoss"
Executor backing this job.
Currently only "PgBoss" is available.
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 * * * *' },
})