Skip to content

Background jobs

Damvia runs its background work with pg-boss, a job queue stored in the same Postgres database as the application. There is no Redis. The worker starts inside the API process when ENABLE_WORKER=true; see Worker and scaling for how to run it.

All queues are declared in server/src/worker.ts. Every job is sent with retryBackoff: true, so a failed job is retried with exponential backoff, and jobs that carry a uniqueKey are deduplicated by pg-boss’s singletonKey.

QueueCronWhat it does
asset/process-deletion* * * * * (every minute)Deletes asset files and folders whose status is pending_deletion: removes the original and thumbnail from the assets bucket and the database rows.
download/process-expired* * * * * (every minute)Marks downloads past their expiresAt as expired and deletes the archive from the assets bucket.
asset/assign-products-to-asset-files*/5 * * * * (every 5 minutes)Matches every asset file name against PRODUCT_MATCHING_REGEX and links it to the product with the captured key. See Products and PIM.
system/integrity-check0 5 * * * (daily at 05:00, server time)Compares the database with the assets bucket, re-queues files whose object is missing or has a different size, and recomputes each collection’s four sample thumbnails. Same code as the check-integrity CLI command.
QueuePushed byWhat it does
asset/update-contentCloud sync (upsertFile), integrity checkDownloads the file from Dropbox or OneDrive, detects its MIME type, uploads the original to asset-file/{id}, generates a WebP thumbnail, reads width and height, sets status up_to_date. Processes 10 jobs at a time (batchSize: 10).
collection/synchronizationLinking a collection to an asset folderMirrors the folder’s sub-tree into the collection tree. One job at a time.
download/create-archivedownload.create with type emailBuilds the file or zip archive, uploads it to downloads/{id}, then pushes mailer/download-ready. One job at a time.
mailer/email-verificationSign-up, “resend verification”Sends the email-verification template with the ?verificationCode= link.
mailer/log-inLogin in passwordless mode or with the magic-link optionSends the login template with a 180-day auth token.
mailer/password-reset“Forgot password”Sends the reset-password template.
email/request-approvalA user verifies their email while still unapprovedSends the request-approval template to every admin and manager of the requester’s region.
email/user-approvedA manager or admin approves a userSends the user-approved template with a login link.
mailer/download-readydownload/create-archiveSends the download-ready template with a presigned link to the archive.
mailer/invitationInviting a guest to a collectionSends the invitation template with a ?dam_token= link that logs the guest in.

Template contents are configured in Email templates.

The 5-minute loop that lists Dropbox or OneDrive and upserts folders and files runs in server/src/index.ts with a plain setTimeout, in every API process, whether or not ENABLE_WORKER is set. It is the sync that pushes asset/update-content jobs; only the download and processing of file contents goes through pg-boss. See Integrations.

A failed job is logged by the worker as job with status: failed, the queue name, the jobId and the error message, then rethrown so pg-boss schedules the retry. pg-boss itself logs connection problems as worker error.