Skip to content

Progress of long operations ​

A deletion or a transfer over thousands of images can take minutes, and the HTTP call only answers at the end. To show a progress bar meanwhile, pass a job id with the request: the API then keeps a document job/<id> up to date in the Firestore database of the project, and a client that listens to that document sees the operation advance.

Tracking is optional. Without job the operation runs exactly the same and only the final answer tells the result.

Starting a tracked operation ​

  1. Create an id for the job: 20 letters and digits, the form of an automatic Firestore document id. With the Firebase SDK, doc(collection(db, 'job')).id gives one.

  2. Send it as job in the JSON body of the request, at the top level or inside data. The CSV route takes its options in the query string, but job goes in the body all the same:

    json
    { "images": ["Qm3xZ0aT9kLw2VbN7cYd", "b8Hn2LpQ5rTs0VwX1yZa"], "job": "Jb7Kq2LmN9pR4sT6vW8x" }
    json
    { "data": { "id": "scratch_light", "job": "Jb7Kq2LmN9pR4sT6vW8x" } }
  3. Listen to the document job/<id>:

    javascript
    import { doc, onSnapshot } from 'firebase/firestore';
    
    const stop = onSnapshot(doc(db, 'job', jobId), (snap) => {
      const job = snap.data();
      if (!job) return;
      console.log(`${job.done} / ${job.total}`, job.phase ?? '');
      if (job.finishedAt) stop();
    });

An id that does not have that form, or one whose document already exists, is ignored and the operation runs untracked. The document is created only after the request passes validation, so a call answered with 400, 404 or 409 leaves no document.

The job document ​

FieldMeaning
typeWhat the operation is: see the table below
datasetId of the dataset the operation runs on. For a transfer, the destination
paramsA few values that describe the operation, such as the name of the dataset or of the tag
startedById of the user who started it
phaseread or write in the operations that have two phases, otherwise null
done, totalHow far the current phase is. They count images
startedAtWhen the operation started
updatedAtLast time the API wrote the document
finishedAtPresent when the operation has ended
resultSummary of a finished operation: the counters of the HTTP answer, with lists given as their length
errorMessage of a failed operation, instead of result

The API writes the progress at most once per second, and at least every 10 seconds while the operation is alive even if nothing advanced. A job whose updatedAt stays still for much longer has been interrupted.

In the operations with two phases, done and total start again when the phase changes from read to write.

The API never deletes job documents: the client that shows the result deletes the document afterwards.

Job types ​

typeRoutePhasesresult
dataset.csv/dataset/{datasetId}/csvread, then write with save_setrows
dataset.zip/dataset/{datasetId}/downloadZipnoneWith storage: true: url, name, size, images, skipped, expiresAt. Without it: name, size, images, skipped
images.copy, images.move/dataset/{datasetId}/operationnoneprocessed, skipped, failed, requested
images.update/dataset/{datasetId}/images/updatenonerequested, updated, missing, failed
images.review/dataset/{datasetId}/reviewactionnoneprocessed
images.delete/dataset/{datasetId}/deleteBulknonerequested, deleted, failed, failedFiles
group.delete/dataset/{datasetId}/group/deletenoneupdated
dataset.delete/dataset/{datasetId}/deletenoneimages, models, annotations, shareTokens, failedFiles
tag.update/dataset/{datasetId}/tag/updateread, then writeupdated
tag.combine/dataset/{datasetId}/tag/combineread, then writeupdated, merged
tag.clear/dataset/{datasetId}/tag/clearread, then writeupdated, failedFiles
tag.delete/dataset/{datasetId}/tag/deleteread, then writeupdated, failedFiles

A tag update opens a job only when it rewrites images: a rename, or a change of color or name in an ANOMALY or MULTILABEL dataset.

The job of a ZIP export made with storage: true carries the download link in its result, so the export can be picked up from the document even if the HTTP call was lost.

Cancelling an export ​

A ZIP export started with a job is cancelled by deleting its job document while it runs. The export notices within about a second while it is advancing, or within 10 seconds otherwise, stops before the next image, removes the unfinished file and answers 499 with The export was cancelled.

The other operations cannot be cancelled: deleting their job document only stops the progress reports, and the operation runs to the end.