- EmDash
- Reference
Job states and record outcomes
Every import and rollback is a job. This page lists the statuses a job moves through, what changes them, and the outcome each record ends with.
A job is one run of a template over one source. It reads the records in batches and keeps a row for each record it read, with what happened to it. You see jobs on the Jobs tab of the Imports page, and through the jobs/* routes and the agent tools.
Kinds of jobs
Section titled “Kinds of jobs”- Import job: reads a source with a template and writes entries. This is what New import, a schedule and the
jobs/createroute make. - Rollback job: undoes what a real import job changed, using that job’s journal. Roll back on the Jobs tab, or
jobs/rollback, makes one. See Rollback jobs.
Either kind can be a dry run or a real run.
Dry runs and real runs
Section titled “Dry runs and real runs”A dry run decides every record exactly as a real run would, and writes nothing: no entries, no terms, no media. Each record row says what the real run would do. The wizard’s Preview step is a dry run, and so is jobs/plan for agents.
| Dry run | Real run | |
|---|---|---|
| Writes entries, terms and media | No | Yes |
| Record rows | planned, with the action it would take |
The outcome |
| Journal (for rollback) | None | Kept by default |
| Retry failed records | Not available | On a completed job |
| Roll back | Not available | On a finished job |
A real run keeps a journal unless it was created with journal: false, which a template with rules.missing refuses. Clear dry runs on the Jobs tab deletes the dry runs that have finished or been idle for an hour, and their staged files once they’ve been idle for an hour. An agent’s dry run that was never started is kept for 24 hours.
Job statuses
Section titled “Job statuses”| Status | Shown as | Meaning |
|---|---|---|
created |
Waiting to start | Created, and no batch has run yet. |
running |
Running | Batches are running, or it’s waiting for the next one. |
paused |
Paused | Stopped by Pause. Nothing runs until it’s resumed. |
completed |
Completed | Every record was read. Some may still have failed. |
failed |
Failed | Stopped by an error that affects the whole job. The error is on the job. |
cancelled |
Cancelled | Stopped by Cancel. It can’t be resumed. |
An import that has a rollback job shows Rolling back until that rollback completes, then Rolled back.
Transitions
Section titled “Transitions”A job starts as created, becomes running when its first batch runs, and ends as completed, failed or cancelled. These actions move it:
| Action | Admin button | Allowed from | Leads to |
|---|---|---|---|
| A batch runs | created, running |
running, then completed after the last record, or failed on a job-level error |
|
| Pause | Pause | created, running |
paused |
| Resume | Resume | paused, failed |
running, with the error cleared |
| Cancel | Cancel | created, running, paused, failed |
cancelled |
| Retry | Retry failed records | completed, real runs only |
running, in a retry pass |
Any other action is refused with invalid_transition, such as Cannot resume a completed job. A job that has been rolled back can’t be resumed or retried. Pausing doesn’t stop a batch that’s already running; it stops the next one.
Cancelling keeps what was already written. The Cancel dialog says so: “Records already written stay.”
How batches run
Section titled “How batches run”A job moves forward one batch at a time, and each batch starts with a call:
- In the admin, the Run step calls
jobs/nextuntil the job ends. Leaving the page pauses nothing, but no batch runs until you come back: Open on the Jobs tab takes you back to it. - An agent calls
jobs/step. - A scheduled job is run by the scheduler, one batch per tick. See Hooks.
A batch is at most batchSize records (50 by default, up to 500) and stops after about budgetMs of work (4,000 ms by default, 500 to 25,000). Only one batch of a job runs at a time: a batch holds a lease on the job, and a second call while it’s held returns the job without doing anything.
Phases
Section titled “Phases”A real or dry import job goes through up to three phases:
- Import: reads every record of the source, in order.
- Missing: only for a template with
rules.missing. After the first pass completes, it counts the owner’s entries that no record had, then moves them to Trash or unpublishes them, unless more thanmaxPercentare missing. See Missing entries. - Retry: after Retry failed records, re-reads the records whose rows are
failed,conflict,lockedorwriting, and decides each again. Rows from the missing phase aren’t retried.
Job-level errors
Section titled “Job-level errors”Most problems fail one record and the job goes on. These stop the whole job and set it to failed, with the code and message on the job:
- The source can’t be read past some point:
csv_syntax,source_syntax,unsupported_encoding,xml_dtd_not_allowedorinvalid_source, with the byte offset. - The staged source file is gone:
source_missing. - The template no longer compiles:
invalid_template. - A rollback’s original job is gone or being deleted:
rollback_original_gone. - An unexpected error three batches in a row:
internal. One or two in a row are kept on the job and the next batch tries again.
Fix the cause, then Resume. Error codes lists every code.
Record outcomes
Section titled “Record outcomes”Each record row has a status:
| Status | Meaning | Counted as |
|---|---|---|
created |
A new entry was created. | created |
updated |
The existing entry was changed. | updated |
unchanged |
The entry already matched, or the record was skipped on purpose (a mode rule, or a missing-phase entry it left alone). A warning says why when it was skipped. |
unchanged |
failed |
The record couldn’t be imported. Its errors say why, by field. | failed |
conflict |
Not written, to protect a change someone else made: the entry has a draft or a schedule this import didn’t make, changed since it was read, or was moved to Trash by an earlier missing phase. | conflict |
locked |
Not written because someone is editing the entry, or, from version 0.9.0, has it open in a co-editing room (EmDash’s coEditing). |
locked |
filtered |
Skipped by the template’s source.filter. |
filtered |
removed |
The missing phase moved the entry to Trash or unpublished it. | removed |
reverted |
A rollback undid the import’s change to this entry. | reverted |
planned |
A dry run’s decision. The row’s action says what a real run would do. |
by action |
writing |
A write had started when the batch stopped. The next batch, a resume or a retry finishes it. | not counted |
A planned row’s action is create, update, unchanged, trash or unpublish in an import dry run, and counts toward created, updated, unchanged or removed. In a rollback dry run it’s delete, trash, revert or restore, and counts as reverted.
Rows also carry the source key, the entry ID, the changes made or planned (field by field, before and after), the terms and media the record created, and any warnings. A row keeps at most 50 errors and 20 warnings; past that, the last one says how many more there were. Download log gives every row as CSV, and Download failed records only the ones that didn’t import.
conflict and locked rows don’t overwrite anyone’s work. Resolve the cause (publish or discard the draft, wait for the editor to finish), then use Retry failed records.
Rollback jobs
Section titled “Rollback jobs”Roll back creates a rollback job for a real import job. It walks the import’s journal newest first and, for each entry the import touched:
- deletes an entry the import created (or moves it to Trash when it can’t be sure the import created it),
- restores an entry the import updated to what it held before,
- restores an entry the missing phase moved to Trash, or republishes one it unpublished.
An entry that changed after the import wrote it is left alone and its row is conflict (rollback_changed). A locked entry is locked. An entry with nothing to undo is unchanged. Terms and media the import created are kept; the rollback job’s warnings list them.
A rollback is refused (invalid_transition) for a rollback job, a dry run, a job without a journal, a job already rolled back, a job that’s created, running or paused (cancel it first), and a job one of whose batches is running.
Rollback jobs use the same statuses. They can be paused and resumed (Continue the rollback), and retried once completed (Retry the rollback), but not cancelled. Their counters add reverted, split into entries deleted, restored and recovered. A rollback with dryRun: true is a dry run: it shows what it would undo and changes nothing. See Rollback.
How long jobs are kept
Section titled “How long jobs are kept”Finished jobs (completed, cancelled, failed) are deleted with their record rows and journal once they’re older than Keep import logs for (days), 30 by default. Jobs that haven’t finished are never deleted. A rolled-back import stays as long as its rollback job does. See Storage.