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.

Five steps in either mode: submit the job with the tenant, the checks before any work starts, stored with the state QUEUED and the answer 202 with the jobId, a copy with a free run place runs the job with the JOpt core, and the result is read with the jobId or announced by a completion webhook.

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:

FieldMeaning
jobIdThe id of the job, made by the server. Keep it private: together with the tenant it reads the job.
creatorHash, identThe creator and the ident of the optimization, as stored
submittedAtWhen the job was accepted
statusACCEPTED
matrixSummaryOnly 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 . _ : -.

CaseAnswer
Same key, same body202 with the same jobId and Idempotent-Replayed: true
Same key, another body422 IDEMPOTENCY_KEY_REUSED
Malformed key, or the header sent twice400 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

A load balancer sends each request to a copy; in the JOpt Platform stack this is Caddy, which picks the least busy copy. A copy accepts the job and puts it into the job queue in MongoDB with the state QUEUED. Copies with a free run place claim jobs; tenants take turns. All copies use the same MongoDB. A stopped copy hands its running jobs back to the queue; a job whose copy is lost goes back once, a second loss ends it as INTERRUPTED.

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 with DNA_COPY_ROLE=accept refuses such a job with 400.
  • DNA_RUN_CAPACITY sets how many jobs one copy runs at a time. In trusted mode the default is UNLIMITED, 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_WAIT limits how long a job may wait. A job that waited longer ends CANCELLED with the stop reason QUEUE_WAIT_EXCEEDED. In trusted mode the default is UNLIMITED.
  • DNA_COPY_ROLE splits the work: accept serves the API and runs no job, run runs 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

A job starts as QUEUED. A copy claims it and it becomes RUNNING. It ends as SUCCESS, ERROR or INTERRUPTED; a job cancelled while it waits ends as CANCELLED. A copy that stops hands its running jobs back to the queue; a job whose copy is lost goes back once, and a second loss ends it as INTERRUPTED. When a job ends, TourOptimizer sends the completion webhook if the job names one.

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.

StateMeaning
QUEUEDThe job waits for a free run place.
RUNNINGA copy runs the job.
SUCCESSThe run ended with its result. stopReason says whether and why it was stopped.
ERRORThe run failed, or the job could not start. message gives the reason.
INTERRUPTEDThe copy that ran the job was lost a second time. If that copy comes back and finishes the run, SUCCESS or ERROR replaces INTERRUPTED.
CANCELLEDThe 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 reasonMeaning
NONEThe run finished on its own
USER_STOPStopped with POST /api/v1/jobs/{jobId}/stop
MAX_RUN_TIMEThe max run time of the job (extension.timeOut) was reached
RUN_TIME_MAXThe max run time of the server or the account was reached
QUEUE_WAIT_EXCEEDEDCancelled because it waited longer than the server allows
TENANT_SUSPENDEDCancelled 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

EndpointWhat it returns
GET /api/v1/jobs/{jobId}/statusThe status entries of the run; Waiting in queue while the job waits
GET /api/v1/jobs/{jobId}/progressThe progress entries, with limit and sortDirection
GET /api/v1/jobs/{jobId}/warningsThe warnings of the run
GET /api/v1/jobs/{jobId}/errorsThe 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

EndpointWhat it returns
GET /api/v1/jobs/{jobId}/resultThe complete optimization with its solution, once the job has ended
GET /api/v1/jobs/{jobId}/solutionThe solution only
POST /api/v1/jobs/{jobId}/request-resultAsks 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-resultThe newest requested result. It is fresh once its version has reached the requestVersion.
GET /api/v1/jobs/{jobId}/exportThe 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

EndpointUseAnswer
POST /api/v1/jobs/{jobId}/stopStops 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}/cancelCancels 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 requestMeaning
extension.timeOutThe 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.expiryThe 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.

FieldMeaning
jobId, tenantIdThe job and its tenant
statusSUCCESS_WITH_SOLUTION, SUCCESS_WITHOUT_SOLUTION, ERROR, INTERRUPTED or CANCELLED
completedAtWhen the job ended
errorMessageOnly for ERROR, INTERRUPTED and CANCELLED
stopReasonAs in the job state
eventId, revisioneventId is the jobId with the revision. A later end of the same job has a higher revision.
attemptThe 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 higher revision wins. GET /api/v1/jobs/{jobId}/state is 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.

PolicyAllowed URLsWhere
noneAny URLTrusted mode, the default
relaxedHTTP and HTTPS, private addresses included; not the loopback addressTrusted mode, set with DNA_WEBHOOK_VALIDATION
strictHTTPS to public addresses onlyAuth mode, always; trusted mode when set

Encryption of stored results

ModeHow a stored result is encrypted
Trusted modeWith 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 modeAlways 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 header X-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/runs starts a run and answers 202 with a runId. The run goes on when the client goes away.
  • GET /api/v1/runs/{runId}/result or /solution waits for the end of the run and returns its result once. If the run has not ended within the wait, the answer is 504 RUN_RESULT_TIMEOUT; ask again with the same runId.
  • GET /api/v1/runs/{runId}/stream/progress, /status, /warnings and /errors are 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 longer extension.timeOut is refused with 403 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).

  • 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