Long-Running Work
Section titled “Long-Running Work”Some operations are too heavy to answer inline: bulk writes over thousands of entries, solution-package export and import, a full dependency-graph rebuild, a background file export. For these the platform answers immediately with a handle, and your client’s job changes from “read the response” to “run the handle to a terminal state”. This page covers the four handle families an external client meets, their polling endpoints and terminal states, what can and cannot be cancelled, and the responses that come back as file downloads rather than JSON.
The general shape — kick off, poll, terminal state — is introduced in Calling the HTTP API. This page is the practitioner’s layer on top: the exact contracts, verified against the services that implement them.
The pattern
Section titled “The pattern”Every family follows the same loop, differing only in the handle and the status vocabulary:
- Kick off. The operation returns a handle — a
messageIdor ajobId/sessionId— instead of a result. - Poll the family’s status endpoint with that handle, at a modest interval with backoff.
- Stop on a terminal state, then read the result from the status payload — which may be a value, a per-row report, or a
fileIdto download.
Two cross-cutting rules:
- Handles are tenant-checked. Polling a job that belongs to another space returns
403; status endpoints verify ownership before answering. - Handles expire. Each family retains status for a limited time (detailed below). Poll promptly and persist results you care about — a handle is not an archive.
For a push-based alternative to step 2, see Progress without polling.
Data-plane jobs: the messageId handle
Section titled “Data-plane jobs: the messageId handle”Heavy data-service operations dispatch a command onto the message bus and return a fresh UUID — the messageId — as the enveloped result. The ones an external client most commonly triggers:
| Operation | Route |
|---|---|
| Bulk update | PATCH /api/v1/entities/{entity}/bulk-update |
| Bulk upgrade | PATCH /api/v3/entities/{entity}/bulk-upgrade |
| Restore entries | PATCH /api/v1/entities/{entity}/restore/entries |
| Background template export | GET /api/v1/entities/{entity}/entries/export/{templateId} (background-type templates) |
Execute a custom-action button Since 1.8 | POST /api/v1/system-buttons/{id} |
Poll the single shared status endpoint:
curl -s "$BASE/api/v1/job/$MESSAGE_ID" -H "x-app-token: $TOKEN"{ "success": true, "result": { "messageId": "1c9a…", "status": "InProgress", // Scheduled | InProgress | Success | Failed "message": { "en": "…", "ar": "…" }, "progress": 40, // 0–100 "result": null // populated on completion, e.g. a per-row report }}The contract (JobStatusResponseDto):
statuswalksScheduled → InProgress → Success | Failed(JobStatusEnum).SuccessandFailedare terminal.- On completion,
resultcarries the operation’s report — for a bulk update, the totals-and-failures DTO that Writing data describes; a partial success is aSuccesswhose report lists failures, so always read the report. - Status lives in a cache with a 24-hour expiry (
JOBS_CACHE_EXPIRY). An unknown or expired handle answers404witherror.code: JOB_STATUS_NOT_EXIST— indistinguishable from a wrong id, so persist anything you need before it ages out. - There is no cancellation for this family: no cancel endpoint exists on the job controller. Once dispatched, the command runs to its own conclusion.
Packaging jobs: BullMQ handles and cancellation
Section titled “Packaging jobs: BullMQ handles and cancellation”packaging-service runs its export and import work on BullMQ queues with dedicated workers, and its status vocabulary is BullMQ’s, normalized at the API boundary.
Export. POST /api/packaging/v1/export enqueues the job and returns {jobId}; poll GET /api/packaging/v1/export/{jobId}/status:
{ "success": true, "result": { "status": "completed", // waiting | waiting-children | active | prioritized | // delayed | completed | failed | unknown "result": { // present when completed "fileId": "…", "name": "package-….zip", "resolvedResources": [ /* what actually went into the package */ ] }, "failedReason": { "message": { "en": "…", "ar": "…" }, "code": "…" } // when failed }}completed and failed are terminal. unknown means the state did not map to the modeled set — keep polling, do not fail (normalizeExportJobStatus). On completion, download the package promptly: the ZIP is uploaded to storage as a temporary file and self-destructs after about a day — see Working with files. Since 1.10 an export also leaves an export record you can list and read later (GET /api/packaging/v1/exports, GET /api/packaging/v1/exports/{id}); deleting one (DELETE …/exports/{id}) removes the record only, not the ZIP in storage (Export records).
Import. Import is session-based: upload the package ZIP to storage, validate it into a session (POST /api/packaging/v1/import/validate with the fileId), then execute — POST /api/packaging/v1/import/{sessionId}/execute returns {jobId, sessionId} and the poll target is the session: GET /api/packaging/v1/import/{sessionId}/status, answering {status, importResult, errorMessage, resourceMappings}. A failed or partially failed session can be re-run with POST …/{sessionId}/retry. The session model and configuration surface are packaging-cluster territory — see Packaging.
Cancellation exists here, with honest semantics (POST /api/packaging/v1/import/{sessionId}/cancel):
- Only a session that is currently
importingorvalidatedcan be cancelled; anything else is a400. - The session is atomically transitioned to
failedwith aCancelled:marker; a concurrent state change surfaces as409. - The response tells you what actually happened to the underlying job:
removed_from_queue(it never started),cancel_requested(it was running — a running worker cannot be hard-killed; it aborts at its next periodic check of the session status), ornot_found(already finished or cleaned up).
So treat cancellation as requested, not instantaneous: after a cancel_requested, keep polling the session until it settles.
The dependency rebuild
Section titled “The dependency rebuild”A full dependency-graph rebuild is the family’s simplest member, with one distinctive behaviour — single concurrency:
POST /api/dependency/v1/rebuildanswers202with{jobId, status: "queued"}.- If a rebuild is already in flight, you get
409— and the error message names the in-flightjobId. The correct reaction is to poll that job, not to retry the kick-off. GET /api/dependency/v1/rebuild/status/{jobId}answers{jobId, state, result?, failedReason?}; an unknown or aged-out id is404.
Tenant backups, restores and exports Since 1.10
Section titled “Tenant backups, restores and exports Since 1.10”In a multi-tenant deployment a tenant’s own system administrator can back up, restore and export the tenant’s data through data-service. It is an API only — there is no web screen for it in 1.10 — and in a single-tenant deployment every route answers 501 BACKUP_NOT_SUPPORTED_IN_SINGLE_MODE. The operator side (the engine, retention, the per-day quotas) is described on the setup section’s backup and restore page; the full HTTP contract and refusal codes are in Tenant backups, restores and exports.
| Kick off | Answers | Poll |
|---|---|---|
POST /api/v1/admin/backups (no body) | 202 with backupId | GET /api/v1/admin/backups/{backupId} |
POST /api/v1/admin/restores ({backupId} or {pointInTime}, plus confirmationToken) | 202 with restoreId | GET /api/v1/admin/restores/{restoreId} |
POST /api/v1/admin/exports | 202 with exportId | GET /api/v1/admin/exports/{exportId} |
What is different about this family:
- A restore is two steps. First
POST /api/v1/admin/restores/previewwith the same target: it answers what the restore would do, with warnings, and a single-useconfirmationTokenthat expires. Then start the restore with that token. A bad, expired or already used token is400 CONFIRMATION_INVALID— ask for a new preview. - A restore puts the tenant under maintenance. From the start until it finishes, every request for the tenant answers
503 TENANT_IN_MAINTENANCEwithRetry-After— exceptGETon/v1/admin/restores…,/v1/admin/backups…and/v1/admin/exports…. Poll the restore with those; do not expect anything else to work, and do not start a second one (409 RESTORE_IN_PROGRESS). - An export is downloaded through a single-use link. When the export is done,
POST /api/v1/admin/exports/{exportId}/linkanswers{url, expiresAt}: a link on the tenant’s own host, usable once, for up to 10 minutes. At most five links per export (linksLefton the export; then409 EXPORT_LINKS_EXHAUSTED). The archive holds the tenant’s databases without user accounts. - Quotas, not load. Starts count against per-day quotas (
backupsPerDay,restoresPerDay,dumpDownloadsPerDay), reported with their reset time byGET /api/v1/admin/backups. Over a quota is429with aRetry-Afterthat runs to the reset. - No cancellation endpoint exists for this family.
Results that are downloads, not JSON
Section titled “Results that are downloads, not JSON”Two different shapes of “the result is a file” exist, and a client must handle both:
Inline downloads. Some operations write the file straight into the HTTP response — the template export endpoint is the canonical case. When the template is configured for inline export, GET /api/v1/entities/{entity}/entries/export/{templateId} sets the file’s content type and an attachment disposition and streams the bytes. These responses bypass the response envelope structurally — there is no {success, result} wrapper and nothing to JSON-parse. The same endpoint returns an enveloped JSON messageId when the template is background-typed, and the request looks identical either way — so branch on the response’s Content-Type header, not on what you expected: application/json means an envelope; anything else is the file itself.
Handle-then-download. Background work that produces a file hands you a fileId instead, and the bytes come from the storage download endpoint as a second request. The packaging export above is one case. The background template export is another, with one indirection: when the file is ready, a notification entry is created for you whose value carries the file descriptor (value.attachment, with reference pointing at the file id), and a notification event is pushed to your user room on the socket. Either way, the final hop is GET /api/storage/v2/files/download/{fileId} — a raw-bytes response with the caveats Working with files spells out, including the one-day lifetime of temporary artifacts.
Progress without polling
Section titled “Progress without polling”Every messageId job doubles as a socket subscription: join the job:{messageId} room and receive the completion event instead of discovering it on the next poll, plus progress updates where the operation reports them. The handshake, the room mechanics and the credential caveat (the socket takes an OAuth token, not an API token) are covered in Subscribing to events.
Use the two channels in their natural division: the socket to wake up, the status endpoint to conclude. The HTTP status is the authoritative record; a socket event is a hint that it is worth reading now.
Where jobs actually run
Section titled “Where jobs actually run”Knowing the machinery helps interpret what you observe:
- Data-plane commands travel the message bus (RabbitMQ) and execute on BullMQ workers inside
data-service(bulk update, upgrade, restore each split into parent, chunk jobs). Completion is written to the Redis-backed job status you poll, then published on the bus as the job-executed event, which the public socket forwards to the browser. (Until 1.10 it travelled through an internal socket relay, since removedRemoved 1.10.) - Packaging and dependency work runs on each service’s own BullMQ queues and workers.
- Tenant backups, restores and exports
Since 1.10are run by the multi-tenant cell’s own controller service;data-serviceonly resolves the calling tenant and relays the request and the status. - Scheduled and recurring work belongs to
scheduler-service, an Agenda-based internal service driven entirely by bus commands — it exposes no client-facing HTTP routes at all (its only HTTP route is a health check). A client cannot schedule work through it directly; recurring behaviour is configured through platform features such as reactions and scheduled reports, which then use it internally.
The practical consequence of all of this: job execution is asynchronous, distributed and at-least-once by design. Build your client to poll with backoff, to treat handles as perishable, and to make acting on a result idempotent.
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27