Skip to content

Commit a97e815

Browse files
committed
fix(jobs): show the collect stage as started while a job collects images
collect_images() persists the collect stage as STARTED for every path (filtered and reprocess-all) immediately after fetching the job, so the UI shows the stage in progress as soon as collection begins instead of only at SUCCESS. The existing throttled progress emit (#1322) is unchanged and carries the STARTED status forward in-memory on the filtered path; reprocess-all has no per-image loop, so this single mark is its only collect heartbeat. Adds tests pinning STARTED on both the filtered and reprocess-all paths.
1 parent d1051e6 commit a97e815

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

ami/ml/models/pipeline.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,15 @@ def collect_images(
233233
"""
234234
task_logger = logger
235235
if job_id:
236-
from ami.jobs.models import Job
236+
from ami.jobs.models import Job, JobState
237237

238238
job = Job.objects.get(pk=job_id)
239239
task_logger = job.logger
240+
# Persist the collect stage as STARTED for every path: the filtered branch's throttle
241+
# below updates only `progress` (never status), and reprocess-all has no loop at all,
242+
# so without this neither path reports STARTED while collection runs.
243+
job.progress.update_stage("collect", status=JobState.STARTED, progress=0)
244+
job.save(update_fields=["progress", "updated_at"])
240245
else:
241246
job = None
242247

ami/ml/tests.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,38 @@ def test_filter_processed_images_skips_progress_emission_without_job(self):
11841184

11851185
self.assertEqual(mock_save.call_count, 0)
11861186

1187+
def test_collect_images_marks_collect_started_on_every_path(self):
1188+
"""
1189+
collect_images() must persist the collect stage as STARTED for every path, otherwise the
1190+
stage keeps its default status during collection and only reports STARTED once collection
1191+
finishes. The filtered path's throttle updates `progress` but never `status`, and the
1192+
reprocess-all path has no per-image loop at all, so neither persists STARTED on its own.
1193+
"""
1194+
from ami.jobs.models import Job, JobState, MLJob
1195+
from ami.ml.models.pipeline import collect_images
1196+
1197+
for reprocess_all in (False, True):
1198+
with self.subTest(reprocess_all=reprocess_all):
1199+
job = Job.objects.create(
1200+
project=self.project,
1201+
name=f"collect-started test (reprocess_all={reprocess_all})",
1202+
pipeline=self.pipeline,
1203+
job_type_key=MLJob.key,
1204+
)
1205+
images = [SourceImage.objects.create(path=f"cs-{reprocess_all}-{i}.jpg") for i in range(3)]
1206+
1207+
list(
1208+
collect_images(
1209+
source_images=images,
1210+
job_id=job.pk,
1211+
pipeline=self.pipeline,
1212+
reprocess_all_images=reprocess_all,
1213+
)
1214+
)
1215+
1216+
job.refresh_from_db()
1217+
self.assertEqual(job.progress.get_stage("collect").status, JobState.STARTED)
1218+
11871219
def test_null_detections_are_algorithm_specific(self):
11881220
"""
11891221
Null detections from different pipelines/algorithms should not be shared.

0 commit comments

Comments
 (0)