Jobs and events options
The keys of the app’s background work and of what it keeps as records change, at the top level of protobase.config.ts.
- Type:
Record<string, JobDeclaration> - Default: none
The app’s jobs by name: what each does, its arguments, when it runs and how it retries. A name is letters, digits, _, -, . and /. What the job does is the default export of jobs/<name>.ts, typed with JobRun from @protobase/server and loaded the first time the job runs; a job without its file stops the app at start with an error that names the file. Jobs shows a job’s config and its jobs/<name>.ts side by side.
export default defineConfig({ jobs: { 'send-invoice': { description: 'Mails an invoice to its customer.', arguments: { invoiceId: 'integer' }, maxAttempts: 5 }, 'daily-report': { schedule: '0 7 * * *' }, },})Each job takes the keys below.
description
Section titled “description”- Type:
string
What the job does, for the people who read the config and the failed jobs page.
jobs: { 'send-invoice': { description: 'Mails an invoice to its customer.' } }arguments
Section titled “arguments”- Type:
Record<string, ArgumentSpec>, each a field type or{ type, optional?, ... }with that type’s options - Default: none
Its arguments by name, each a field type such as 'bigint', or the type with options, such as { type: 'enum', values: ['day', 'week'] } or { type: 'integer', optional: true }. Each is checked when the job is enqueued and again before it runs, and no other argument is taken.
jobs: { 'send-report': { arguments: { period: { type: 'enum', values: ['day', 'week'] }, userId: 'text' } } }maxAttempts
Section titled “maxAttempts”- Type:
number - Default:
10
Tries before the job is kept as failed, listed in the admin app. See Failures.
jobs: { 'send-invoice': { maxAttempts: 5 } }retryDelay
Section titled “retryDelay”- Type:
number | string - Default:
2s
The wait before the first retry, doubling with each one: milliseconds, or text such as 30 seconds.
jobs: { 'sync-crm': { retryDelay: '30 seconds' } }maxRetryDelay
Section titled “maxRetryDelay”- Type:
number | string - Default:
1 hour
The longest wait between two tries.
jobs: { 'sync-crm': { maxRetryDelay: '10 minutes' } }timeout
Section titled “timeout”- Type:
number | string - Default:
15 minutes
How long one try may run before it counts as failed.
jobs: { 'import-products': { timeout: '1 hour' } }longQueries
Section titled “longQueries”- Type:
boolean - Default:
false
Its queries through db may run up to 30 seconds instead of the database’s own limit, on a connection kept for such work: for imports, backfills, large deletes and other bulk work. See Long queries.
jobs: { 'import-products': { longQueries: true } }concurrency
Section titled “concurrency”- Type:
number - Default:
1
Jobs of this name running at once in each worker process.
jobs: { 'send-invoice': { concurrency: 4 } }ordered
Section titled “ordered”- Type:
boolean - Default:
false
Jobs run one at a time per group, in the order they were enqueued, and every enqueue names its group. Turning it on or off for a job whose queue exists stops the app at start. See Ordered groups.
jobs: { 'sync-order': { ordered: true } }schedule
Section titled “schedule”- Type:
string, a cron expression
Runs the job on this cron schedule, such as 0 7 * * * (with an optional seconds field first), with no payload: one run per time, however many workers run. See Recurring jobs.
jobs: { 'daily-report': { schedule: '0 7 * * *' } }timezone
Section titled “timezone”- Type:
string - Default: the config’s
timezone, elseUTC
The time zone schedule is read in, such as Europe/Amsterdam, so 07:00 stays 07:00 across daylight saving time.
jobs: { 'daily-report': { schedule: '0 7 * * *', timezone: 'Europe/Amsterdam' } }events.schema
Section titled “events.schema”- Type:
string - Default:
changes
The schema holding the outbox and the capture function that resources’ events are raised from, and the prefix of their transaction settings (changes.actor, changes.capture). Rename it when the database already has a schema by that name; lowercase letters, digits and _. See How changes are captured.
export default defineConfig({ events: { schema: 'app_changes' } })history.days
Section titled “history.days”- Type:
number, a positive whole number - Default: kept forever
Days a change of a resource with .history() is kept; a daily job deletes older ones. See Record history.
export default defineConfig({ history: { days: 365 } })webhooks
Section titled “webhooks”- Type:
{ schema?: string; deliveryLog?: boolean; allowPrivateAddresses?: boolean } - Default: off;
{}turns them on
Webhook subscriptions that people make in the admin app, kept in a table of the app’s database that protobase migration writes. A subscription delivers as its owner, with the roles they hold now, read from the app’s sign-in; a project that signs people in otherwise exports its own, async ({ id, tenant }) => [...], as the default of webhooks/owner-roles.ts. See Subscriptions in the admin app.
export default defineConfig({ webhooks: {} })webhooks.schema
Section titled “webhooks.schema”- Type:
string - Default:
webhooks
The schema of the subscriptions table and the deliveries view.
export default defineConfig({ webhooks: { schema: 'hooks' } })webhooks.deliveryLog
Section titled “webhooks.deliveryLog”- Type:
boolean - Default:
false
Also keeps every try, successes too, for 30 days, listed as the Webhook delivery log.
export default defineConfig({ webhooks: { deliveryLog: true } })webhooks.allowPrivateAddresses
Section titled “webhooks.allowPrivateAddresses”- Type:
boolean - Default:
false
Lets subscriptions send to private, loopback and link-local addresses, for development and tests. Off, a URL whose host resolves to one is refused when the subscription is saved and again at each delivery, which connects only to the address it checked, so a subscription cannot reach the app’s own network.
export default defineConfig(({ command }) => ({ webhooks: { allowPrivateAddresses: command === 'dev' } }))workflows
Section titled “workflows”- Type:
{ schema?: string; secrets?: string[]; allowPrivateAddresses?: boolean; plugins?: string[]; storage?: { root?: string; endpoints?: string[] }; customSteps?: boolean; runners?: { claimSeconds?: number; leaseSeconds?: number; coldWaitSeconds?: number; warmWaitSeconds?: number } } - Default: off;
{}turns them on
Workflows that people and models make in the app, kept with their versions, runs and steps in a schema of the app’s database that protobase migration writes, and run by the workflows.segment job. Records steps act as each workflow’s last editor, with the roles they hold now, read from the app’s sign-in; a project that signs people in otherwise exports its own, async ({ id, tenant }) => [...], as the default of workflows/saved-by-roles.ts. See Workflows.
export default defineConfig({ workflows: {} })workflows.schema
Section titled “workflows.schema”- Type:
string - Default:
workflows
The schema of the workflows, their versions, runs and steps.
export default defineConfig({ workflows: { schema: 'flows' } })workflows.secrets
Section titled “workflows.secrets”- Type:
string[] - Default: none
The environment variables workflows may read, each as $states.context.Secrets.<NAME>; no other variable is reachable from a workflow. Their values are blanked out of everything a run records but its input, which is kept as its caller gave it. Startup stops when one is unset or shorter than 8 characters.
export default defineConfig({ workflows: { secrets: ['TICKETS_TOKEN'] } })workflows.allowPrivateAddresses
Section titled “workflows.allowPrivateAddresses”- Type:
boolean - Default:
false
Lets the app:http step, and every plugin’s fetch, reach private, loopback and link-local addresses, for development and tests. Off, a URL whose host resolves to one fails the request, which connects only to the address it checked, so a workflow cannot reach the app’s own network.
export default defineConfig(({ command }) => ({ workflows: { allowPrivateAddresses: command === 'dev' } }))workflows.plugins
Section titled “workflows.plugins”- Type:
string[] - Default: none
Packages of workflow plugins the app runs, by package name, beside the built-in types and the app’s own plugins in workflows/plugins/<name>.ts. Two plugins of one name stop startup, naming both.
export default defineConfig({ workflows: { plugins: ['@acme/workflow-plugin'] } })workflows.storage
Section titled “workflows.storage”- Type:
{ root?: string; endpoints?: string[] } - Default: off
Turns on storage configurations, the named places workflows store files in. root is the one folder local configurations live inside, such as a mounted file share; it must not overlap a file provider’s folder. Without it, only S3-compatible configurations are taken. endpoints are the https:// origins an S3-compatible configuration may name; without them, none are taken. S3-compatible configurations cannot be used while the server’s environment sets S3_ENDPOINT, AWS_ENDPOINT, S3_REGION, AWS_REGION, S3_SESSION_TOKEN or AWS_SESSION_TOKEN, since the S3 client would sign their requests with them. The configurations’ keys are encrypted, so the app needs PROTOBASE_ENCRYPTION_KEY.
export default defineConfig({ workflows: { storage: { root: './data/workflow-storage', endpoints: ['https://storage.example.com'] } } })workflows.customSteps
Section titled “workflows.customSteps”- Type:
boolean - Default:
false
Turns on custom steps, step types the app’s authors keep as records, each saved version a type of its own, custom:<name>:<version>, and the runners that run them. Their tables come with the next protobase migration after you turn them on. Their jobs’ arguments are sealed with the app’s secret, its sign-in’s (auth), else PROTOBASE_SECRET, so startup stops without either. Any other value than true or false stops startup.
export default defineConfig({ workflows: { customSteps: true } })workflows.runners
Section titled “workflows.runners”- Type:
{ claimSeconds?: number; leaseSeconds?: number; coldWaitSeconds?: number; warmWaitSeconds?: number } - Default:
{ claimSeconds: 50, leaseSeconds: 30, coldWaitSeconds: 5, warmWaitSeconds: 1 }
How custom steps’ jobs reach runners, with customSteps on, each in seconds: how long a claim is held open waiting for a job (claimSeconds), how long a runner holds a job without a heartbeat before it goes back to the queue (leaseSeconds), how long a job whose best free runner lacks its image waits for one that has it (coldWaitSeconds), and how long a job whose best free runner has its image waits for a warm instance (warmWaitSeconds), as How jobs are placed says. Startup stops on a setting it does not know, a time that is no number above 0, or a wait below 0.
export default defineConfig({ workflows: { customSteps: true, runners: { coldWaitSeconds: 10 } } })notifications
Section titled “notifications”- Type:
{ ui?: boolean; schema?: string; devices?: { table?: string; columns?: Record<string, string> }; history?: { table?: string; columns?: Record<string, string> } } - Default: off;
{}turns them on
Each user’s devices and inbox: the bell in the top bar and push on their browsers, over tables that protobase migration writes. Web Push is on when the PROTOBASE_VAPID_* variables are set. See Notifications.
Three files replace the built-in parts, each as its default export: notifications/store.ts a device store in place of the devices table, notifications/history-store.ts a history store in place of the history table, and notifications/senders.ts an array of push senders in place of the built-in ones. See Your own parts.
export default defineConfig({ notifications: {} })notifications.ui
Section titled “notifications.ui”- Type:
boolean - Default:
true
The bell in the top bar; false keeps only the backend. See Without the bell.
export default defineConfig({ notifications: { ui: false } })notifications.schema
Section titled “notifications.schema”- Type:
string - Default:
notifications
The schema of the built-in tables.
export default defineConfig({ notifications: { schema: 'inbox' } })notifications.devices
Section titled “notifications.devices”- Type:
{ table?: string; columns?: Record<string, string> } - Default:
{ table: 'devices' }
The devices table: its name, and its columns named otherwise than Protobase names them. See Table names.
export default defineConfig({ notifications: { devices: { table: 'push_devices', columns: { user_id: 'owner_id' } } } })notifications.history
Section titled “notifications.history”- Type:
{ table?: string; columns?: Record<string, string> } - Default:
{ table: 'history' }
The history table, each user’s inbox: its name, and its columns named otherwise than Protobase names them.
export default defineConfig({ notifications: { history: { table: 'inbox_items' } } })status
Section titled “status”- Type:
{ schema?: string } - Default: off;
{}turns it on
People set their own status, busy, do not disturb or a text of their own, which the people they share an organization with see, and do not disturb holds their pushes. It needs auth with organizations, and its table is written by protobase migration. See Status.
export default defineConfig({ auth: { organizations: true }, status: {} })status.schema
Section titled “status.schema”- Type:
string - Default:
status
The schema of the statuses table.
export default defineConfig({ status: { schema: 'presence' } })unsubscribe
Section titled “unsubscribe”- Type:
boolean - Default:
false
Gives bulk mail a one-click unsubscribe: mail a job sends with bulk: true and a topic carries the recipient’s own unsubscribe link, and is not sent to whoever unsubscribed from its topic. The links are on url and signed with secret, and the table of who unsubscribed, mail.unsubscribes, is written by protobase migration as a migration of the project’s own: apply it with the project’s migrations, as protobase serve refuses to start while the table is missing. See Unsubscribe.
export default defineConfig({ unsubscribe: true })mailFeedback
Section titled “mailFeedback”- Type:
boolean - Default:
false
Takes the bounces and spam complaints of the mail the app sends as mail_feedback records, with the events mail_feedback.bounced and mail_feedback.complained, at POST /api/mail/feedback/<provider> for each provider whose variable is set. The table, mail.feedback, and the capture of its events are written by protobase migration as migrations of the project’s own: apply them with the project’s migrations, as protobase serve refuses to start while the table is missing. See Bounces and complaints.
export default defineConfig({ mailFeedback: true })