Jobs
A job is an optimization that TourOptimizer stores, queues, runs and keeps. The client submits it, gets a jobId at once and reads the state and the result later, from any copy of TourOptimizer. Jobs work the same in both modes. They need MongoDB: in trusted mode set DNA_DATABASE_ACTIVE=true (Trusted Mode); the JOpt Platform stack always has it.
The diagram opens full size on click.
Submit a job
POST /api/v1/jobs takes the JSON of an optimization (API and clients). Before it stores anything, TourOptimizer runs its admission checks (Checks and limits). A job that passes is stored with the state QUEUED, and the answer is 202 with a JobAcceptedResponse:
| Field | Meaning |
|---|---|
jobId | The id of the job, made by the server. Keep it private: together with the tenant it reads the job. |
creatorHash, ident | The creator and the ident of the optimization, as stored |
submittedAt | When the job was accepted |
status | ACCEPTED |
matrixSummary | Only for a job with geo data: what the distance matrix holds |
To store the result, set extension.persistenceSetting.mongoSettings.enablePersistence to true. A job without it runs, but its result is not stored.
Retry a submit safely
A 202 can get lost on the network. Send the optional header Idempotency-Key with the submit: a retry with the same key and the same body returns the same jobId with the header Idempotent-Replayed: true and makes no second job. The key is 1 to 64 characters of letters, digits and . _ : -.
| Case | Answer |
|---|---|
| Same key, same body | 202 with the same jobId and Idempotent-Replayed: true |
| Same key, another body | 422 IDEMPOTENCY_KEY_REUSED |
| Malformed key, or the header sent twice | 400 IDEMPOTENCY_KEY_INVALID |
Jobs with geo data
In the JOpt Platform stack, POST /api/v1/jobs/withGeoProvider takes the optimization and geoConnectionSettings. TourOptimizer fetches the distance and driving-time matrix from GeoCoderRouter at the submit, adds it to the job and queues the job like POST /api/v1/jobs. Connections that the request already holds are never replaced.
The queue and the copies
The diagram opens full size on click.
- Several copies of TourOptimizer share one MongoDB and one job queue. Any copy accepts a submit, and any copy answers the reads of any job.
- A copy with a free run place claims the next job. Tenants take turns; within a tenant the oldest job starts first.
- In trusted mode a job that brings its own license or encryption secret runs only on the copy that accepted it: that copy holds them in memory and never stores them. If that copy stops before the job ends, the job ends with
ERROR. A copy withDNA_COPY_ROLE=acceptrefuses such a job with400. DNA_RUN_CAPACITYsets how many jobs one copy runs at a time. In trusted mode the default isUNLIMITED, so every job starts at once.- In auth mode the plan of the tenant also limits how many of its jobs run at a time and how many wait.
DNA_QUEUE_MAX_WAITlimits how long a job may wait. A job that waited longer endsCANCELLEDwith the stop reasonQUEUE_WAIT_EXCEEDED. In trusted mode the default isUNLIMITED.DNA_COPY_ROLEsplits the work:acceptserves the API and runs no job,runruns jobs and serves no API request,both(the default) does both.- A copy that stops in an orderly way hands its running jobs back to the queue. Another copy starts them again from their input.
- A job whose copy is lost goes back to the queue once and starts over. A second loss ends it as
INTERRUPTED.
The settings are on Settings.
Job states
The diagram opens full size on click.
GET /api/v1/jobs/{jobId}/state returns the state of a job. It is the source of truth for whether a job has ended.
| State | Meaning |
|---|---|
QUEUED | The job waits for a free run place. |
RUNNING | A copy runs the job. |
SUCCESS | The run ended with its result. stopReason says whether and why it was stopped. |
ERROR | The run failed, or the job could not start. message gives the reason. |
INTERRUPTED | The copy that ran the job was lost a second time. If that copy comes back and finishes the run, SUCCESS or ERROR replaces INTERRUPTED. |
CANCELLED | The job was cancelled while it waited and never ran, or it was stopped and its copy was lost before the run could end. It has no result. |
| Stop reason | Meaning |
|---|---|
NONE | The run finished on its own |
USER_STOP | Stopped with POST /api/v1/jobs/{jobId}/stop |
MAX_RUN_TIME | The max run time of the job (extension.timeOut) was reached |
RUN_TIME_MAX | The max run time of the server or the account was reached |
QUEUE_WAIT_EXCEEDED | Cancelled because it waited longer than the server allows |
TENANT_SUSPENDED | Cancelled while it waited because the subscription of the account ended (auth mode) |
The answer also holds submittedAt, startedAt, endedAt, keepUntil, maxRunTime, keep, message and revision. The max run time counts from startedAt, not from the submit.
To find jobs, POST /api/v1/jobs/state/search searches by state (waiting jobs included) and POST /api/v1/jobs/status/search by the status entries. POST /api/v1/jobs/search searches the stored results by their metadata when the server allows free search.
Progress, status, warnings and errors
| Endpoint | What it returns |
|---|---|
GET /api/v1/jobs/{jobId}/status | The status entries of the run; Waiting in queue while the job waits |
GET /api/v1/jobs/{jobId}/progress | The progress entries, with limit and sortDirection |
GET /api/v1/jobs/{jobId}/warnings | The warnings of the run |
GET /api/v1/jobs/{jobId}/errors | The errors of the run |
TourOptimizer stores these entries only when the job asks for them, in mongoSettings.streamPersistenceStrategySetting: saveStatus, saveProgress, saveWarning and saveError. With cycleStatus or cycleProgress it keeps only the newest entry.
Results
| Endpoint | What it returns |
|---|---|
GET /api/v1/jobs/{jobId}/result | The complete optimization with its solution, once the job has ended |
GET /api/v1/jobs/{jobId}/solution | The solution only |
POST /api/v1/jobs/{jobId}/request-result | Asks the running job for its best result so far; the run goes on. The answer 202 carries a requestVersion. |
GET /api/v1/jobs/{jobId}/request-result | The newest requested result. It is fresh once its version has reached the requestVersion. |
GET /api/v1/jobs/{jobId}/export | The stored result as a ZIP archive |
A request for a running job reaches the copy that runs it within one heartbeat, 15 seconds by default. A result that the client encrypted with its own secret is read with the header X-Encryption-Secret (trusted mode). The result never holds the license, the webhook signing secret or the encryption secret.
Stop, cancel and delete
| Endpoint | Use | Answer |
|---|---|---|
POST /api/v1/jobs/{jobId}/stop | Stops a running job. The run ends with its best result and the stop reason USER_STOP. | 200; 404 when the job does not run (it waits, has ended or belongs to another tenant) |
POST /api/v1/jobs/{jobId}/cancel | Cancels a waiting job. It becomes CANCELLED and never runs. Its data is kept for the keep time, counted from the cancel. | 200 with the state; 409 JOB_NOT_QUEUED when the job runs or has ended |
DELETE /api/v1/jobs/{jobId} | Deletes all data of the job for good. It does not stop a run: stop the job first. | 200, also when nothing was there |
A stop reaches the copy that runs the job within one heartbeat. If that copy stops after the stop reached the run, the run still ends with its best result. If the run does not end within the stop grace, 60 seconds by default, or the copy is lost before the stop reaches it, the job ends CANCELLED without a result.
Run time and keep time
| Field of the request | Meaning |
|---|---|
extension.timeOut | The max run time, counted from the start of the run. At this time the run stops and keeps its best result. An ISO 8601 duration such as PT30M, or UNLIMITED. Not set: the run ends by itself, within the max run time of the server or the account. |
mongoSettings.expiry | The keep time: how long all data of the job is kept, counted from the end of the run. An ISO 8601 duration such as P7D, or UNLIMITED. Not set: the default keep time of the server or the account. Nothing of a running job is deleted. |
A bare number is refused with 400 in both fields; 0 or a negative value still means UNLIMITED but is deprecated. A value above the limit of the server or the account is refused with 403 RUN_TIME_LIMIT_EXCEEDED or 403 KEEP_TIME_LIMIT_EXCEEDED. A cleaner deletes the jobs whose keep time is over at a fixed interval, every two hours by default. The server limits are on Settings.
Completion webhooks
When a job ends, TourOptimizer sends a POST to the URL the job names in mongoSettings.completionWebhookUrl. The message says that the job has ended; it carries no optimization data. Read the result with the jobId.
| Field | Meaning |
|---|---|
jobId, tenantId | The job and its tenant |
status | SUCCESS_WITH_SOLUTION, SUCCESS_WITHOUT_SOLUTION, ERROR, INTERRUPTED or CANCELLED |
completedAt | When the job ended |
errorMessage | Only for ERROR, INTERRUPTED and CANCELLED |
stopReason | As in the job state |
eventId, revision | eventId is the jobId with the revision. A later end of the same job has a higher revision. |
attempt | The number of this delivery |
The headers X-JOpt-Event-Id and X-JOpt-Event-Revision repeat eventId and revision.
Check the signature
Set mongoSettings.completionWebhookSecret and every delivery carries the header X-JOpt-Signature in the form sha256=<hex>: an HMAC-SHA256 of the raw body with that secret. Compute the same HMAC over the raw body and compare the two in constant time. Without a secret the header reads sha256=unsigned.
Delivery and retries
- TourOptimizer waits 10 seconds for an answer and follows no redirect. An answer with a 2xx status ends the delivery.
- Otherwise it tries again after 1, 5 and 15 minutes, then every hour, up to the attempt limit (
DNA_WEBHOOK_MAX_ATTEMPTS, 5 by default). - Delivery is at least once. Drop a repeated
eventId; of two messages for one job, the higherrevisionwins.GET /api/v1/jobs/{jobId}/stateis the source of truth. - A newer end of a job replaces an older message that was not delivered yet.
Which URLs are allowed
TourOptimizer checks the URL at the submit and again at every delivery. A URL that is not allowed is refused with 400 WEBHOOK_URL_NOT_ALLOWED.
| Policy | Allowed URLs | Where |
|---|---|---|
none | Any URL | Trusted mode, the default |
relaxed | HTTP and HTTPS, private addresses included; not the loopback address | Trusted mode, set with DNA_WEBHOOK_VALIDATION |
strict | HTTPS to public addresses only | Auth mode, always; trusted mode when set |
Encryption of stored results
| Mode | How a stored result is encrypted |
|---|---|
| Trusted mode | With the secret of the client in mongoSettings.secret, if the job sends one. Otherwise with a key per tenant, if the server has a master key (DNA_TO_MASTER_KEY, see Settings). Otherwise not encrypted. |
| Auth mode | Always with a key per tenant from the JOpt Platform stack. A job that sends its own secret is refused with 400 ENCRYPTION_SECRET_NOT_ALLOWED. |
- A secret of the client must be strong; a weak one is refused with
400 ENCRYPTION_SECRET_WEAK. TourOptimizer does not store it: a lost secret cannot be restored. Reads send it in the headerX-Encryption-Secret. - With the secret of the client, the result is encrypted with AES-GCM and a key derived from the secret with PBKDF2-HMAC-SHA256. The creator, the ident, the time stamp and the status are then not stored in clear, so a search does not find them.
- With the key per tenant, these metadata stay readable for the search.
- The texts of warnings and errors are encrypted with the key per tenant; status and progress entries are stored in clear.
- The webhook URL and its signing secret are stored encrypted in the job record.
Synchronous runs and live streams (trusted mode)
For short optimizations, trusted mode also offers runs that are not stored.
POST /api/v1/runsstarts a run and answers202with arunId. The run goes on when the client goes away.GET /api/v1/runs/{runId}/resultor/solutionwaits for the end of the run and returns its result once. If the run has not ended within the wait, the answer is504 RUN_RESULT_TIMEOUT; ask again with the samerunId.GET /api/v1/runs/{runId}/stream/progress,/status,/warningsand/errorsare server-sent event streams. A client that connects late gets the events from the start.DELETE /api/v1/runs/{runId}stops the run.- The result is kept in the memory of the copy only, until one request has read it, and is lost on a restart.
- A run may last at most the synchronous run time limit,
DNA_SYNC_RUN_TIME_MAX(one hour by default). A longerextension.timeOutis refused with403 SYNC_RUN_TIME_LIMIT_EXCEEDED; submit it as a job.
Auth mode has no synchronous runs and no live streams: there, every optimization is a job.
Import a result (trusted mode)
POST /api/v1/jobs/import stores an optimization with its solution as a job, without a run, for example a result computed with the Java SDK. The answer is a JobAcceptedResponse, and the result is read like any other. The job must have enablePersistence set, and the server must allow imports (DNA_DATABASE_JOB_IMPORT_ENABLED, on by default).
Related pages
- API and clients: the endpoint groups, the headers and the JSON model
- Checks and limits: the checks before a job is stored and the reason codes
- Settings: the queue, run time, keep time, webhook and encryption settings
- JOpt Platform: TourOptimizer in auth mode, with GeoCoderRouter
Added: 2026-11-27 | Last updated: 2026-11-27