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
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')).idgives one.Send it as
jobin the JSON body of the request, at the top level or insidedata. The CSV route takes its options in the query string, butjobgoes in the body all the same:json{ "images": ["Qm3xZ0aT9kLw2VbN7cYd", "b8Hn2LpQ5rTs0VwX1yZa"], "job": "Jb7Kq2LmN9pR4sT6vW8x" }json{ "data": { "id": "scratch_light", "job": "Jb7Kq2LmN9pR4sT6vW8x" } }Listen to the document
job/<id>:javascriptimport { 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
| Field | Meaning |
|---|---|
type | What the operation is: see the table below |
dataset | Id of the dataset the operation runs on. For a transfer, the destination |
params | A few values that describe the operation, such as the name of the dataset or of the tag |
startedBy | Id of the user who started it |
phase | read or write in the operations that have two phases, otherwise null |
done, total | How far the current phase is. They count images |
startedAt | When the operation started |
updatedAt | Last time the API wrote the document |
finishedAt | Present when the operation has ended |
result | Summary of a finished operation: the counters of the HTTP answer, with lists given as their length |
error | Message 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
type | Route | Phases | result |
|---|---|---|---|
dataset.csv | /dataset/{datasetId}/csv | read, then write with save_set | rows |
dataset.zip | /dataset/{datasetId}/downloadZip | none | With storage: true: url, name, size, images, skipped, expiresAt. Without it: name, size, images, skipped |
images.copy, images.move | /dataset/{datasetId}/operation | none | processed, skipped, failed, requested |
images.update | /dataset/{datasetId}/images/update | none | requested, updated, missing, failed |
images.review | /dataset/{datasetId}/reviewaction | none | processed |
images.delete | /dataset/{datasetId}/deleteBulk | none | requested, deleted, failed, failedFiles |
group.delete | /dataset/{datasetId}/group/delete | none | updated |
dataset.delete | /dataset/{datasetId}/delete | none | images, models, annotations, shareTokens, failedFiles |
tag.update | /dataset/{datasetId}/tag/update | read, then write | updated |
tag.combine | /dataset/{datasetId}/tag/combine | read, then write | updated, merged |
tag.clear | /dataset/{datasetId}/tag/clear | read, then write | updated, failedFiles |
tag.delete | /dataset/{datasetId}/tag/delete | read, then write | updated, 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.