Background jobs
The jobs capability adds a persistent queue and one background worker. A signed-in user picks a file; the app reads it once with that session and keeps a private copy in the package’s data folder, which the worker processes after sign-out into a SHA-256 digest. A job never writes to the user’s folders; that needs Delegate.
Add it
Section titled “Add it”synopkgland init -t native-go --with jobs my-jobsFor an existing project, run synopkgland add jobs. Both write:
capabilities: jobs: truejobs: true is the same as jobs: { worker: sha256-v1 }; no other worker name is accepted. delegate also turns jobs on.
| Combination | Result |
|---|---|
With daemon | CAPABILITY_COMBINATION_INVALID unless delegate uses lifetime: until-revoked |
| With a binary backend | CAPABILITY_UNSUPPORTED |
The Vue UI adds a Background jobs page; a plain UI has none. armv7 builds are unverified (Platforms).
Submit, watch and cancel
Section titled “Submit, watch and cancel”The page lets a user pick a file, submit, watch, cancel and see the result; your code calls the same methods through ctx.call. All need a signed-in user and run as the package account without credentials. bg.browse lists files the user may pick, without files.
| Method | Params | Result |
|---|---|---|
bg.status | {} | Limits, counts |
bg.jobs.submit | { key, folder, relative } | { job, duplicate } |
bg.jobs.list | {} | { jobs }, newest first |
bg.jobs.get, bg.jobs.cancel | { id } | { job } |
bg.jobs.result | { id } | { job, result } or not_ready |
const key = crypto.randomUUID()const { job } = await ctx.call<{ job: { id: string; state: string } }>('bg.jobs.submit', { key, folder: '/home', relative: 'report.txt',})const { result } = await ctx.call<{ result: { sha256: string; bytes: number } }>('bg.jobs.result', { id: job.id })keyis 1 to 64 letters, digits, dots, underscores and hyphens; reusing it returns the same job withduplicate: true, so retries are safe; keys are per owner.folderis a File Station path;relativea file below it.- The result is JSON, not a file:
{ jobId, worker, workerRevision, algorithm: "sha256", sha256, bytes, inputDigest, name }. - A job moves through
queuedandrunning, then ends assucceeded,failed,canceledorinterrupted; one running when the worker stops isinterruptedand is never replayed. Onlybg.jobs.cancelcancels it.
Schedules
Section titled “Schedules”After an import, the owner can schedule that copy. The app pins the bytes and digest and never reads the NAS file again, so later source changes do not matter.
| Method | Params and access |
|---|---|
bg.schedules.list | {}; owners see their own, administrators all |
bg.schedules.create | { key, jobId, intervalSeconds, consent: true }; source-job owner |
bg.schedules.disable, bg.schedules.delete | { id }; owner or administrator |
bg.schedules.enable | { id, consent: true }; administrators only |
intervalSecondsis3600,86400or604800;consentmust betrueor the call fails withbad_request.jobIdmust be your own job withsucceeded; an unfinished job, a scheduled run or a gone copy returnsinput-unavailable.- The pin counts toward your 1 MiB and the 16 MiB package limit; scheduled runs leave 4 queue slots for manual jobs. Late ticks are not made up: a schedule is not exact-time or exactly-once.
Who sees which job
Section titled “Who sees which job”An owner is a DSM user name together with the numeric UID that DSM resolves for it.
- Ordinary users list, read, cancel and get their own jobs only; a missing job ID and another owner’s job both return
not_found. - An administrator sees and cancels all jobs;
bg.jobs.purge({ owner: { user, uid } }) removes one owner’s jobs and is administrator-only. - If DSM cannot resolve the UID, the call fails with
identity_unavailable; for administrators this affects only submit and schedule create. A recreated account with a new UID cannot reach earlier jobs.
Limits
Section titled “Limits”| Item | Limit |
|---|---|
| Jobs running at once / queued | 1 / 16 |
| Input file | 512 KiB; 60 seconds per job |
| Total private copies and results / pending jobs per owner | 16 MiB / 2 jobs |
| Private data per owner | 1 MiB, plus 512 bytes per kept result |
| Finished jobs / schedules per package | 64 / 8 |
The data lives in the package’s app data folder and survives stop and uninstall; see Data and removal.
Troubleshooting
Section titled “Troubleshooting”See Errors for every code.
| Code | Cause and fix |
|---|---|
session_required, dsm_session_required | No signed-in user or DSM session. Sign in again; with standalone login the call needs the DSM id cookie |
limit-exceeded, queue-full | The file is over 512 KiB, or 16 jobs are queued. Use a smaller file, or wait |
quota-exceeded, owner-queue-full, owner-quota-exceeded | 16 MiB, 2 pending jobs or 1 MiB of data. Wait, cancel, or ask an administrator |
not_found, not_ready, conflict | Another owner’s job, no result yet, or a reused key. Refresh, wait, or new key |
schedule-full, input-unavailable | 8 schedules, or the kept copy is gone. Delete one, or import again |
identity_unavailable | DSM could not resolve the UID. Retry; check the DSM account |
jobs_busy, admin_required | The job store was locked over 5 seconds, or the method is administrator-only |