Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance task_status to handle job states correctly #1806

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions monailabel/datastore/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,51 @@
return task_id, task_name

def task_status(self):
"""
Fetches the status of a CVAT task based on the state of its jobs.
Returns:
- "completed" if all jobs are completed.
- "in_progress" if at least one job is not completed.
- None if an error occurs or the task does not exist.
"""
# Get the project and task IDs
project_id = self.get_cvat_project_id(create=False)
if project_id is None:
return None

task_id, _ = self.get_cvat_task_id(project_id, create=False)
if task_id is None:
return None

r = requests.get(f"{self.api_url}/api/tasks/{task_id}", auth=self.auth).json()
return r.get("status")
# Fetch task details
task_url = f"{self.api_url}/api/tasks/{task_id}"
task_response = requests.get(task_url, auth=self.auth)

if task_response.status_code != 200:
return None # Task could not be fetched

Check warning on line 160 in monailabel/datastore/cvat.py

View check run for this annotation

Codecov / codecov/patch

monailabel/datastore/cvat.py#L160

Added line #L160 was not covered by tests

task_data = task_response.json()

# Get the jobs URL from the task details
jobs_url = task_data.get("jobs", {}).get("url")
if not jobs_url:
return None # No jobs URL found for the task

# Fetch jobs for the task
jobs_response = requests.get(jobs_url, auth=self.auth)
if jobs_response.status_code != 200:
return None # Jobs could not be fetched

Check warning on line 172 in monailabel/datastore/cvat.py

View check run for this annotation

Codecov / codecov/patch

monailabel/datastore/cvat.py#L170-L172

Added lines #L170 - L172 were not covered by tests

# Parse jobs and check their states
jobs = jobs_response.json().get("results", [])
if not jobs:
return None # No jobs found for the task

Check warning on line 177 in monailabel/datastore/cvat.py

View check run for this annotation

Codecov / codecov/patch

monailabel/datastore/cvat.py#L175-L177

Added lines #L175 - L177 were not covered by tests

# Check if all jobs have state "completed"
all_completed = all(job.get("state") == "completed" for job in jobs)

Check warning on line 180 in monailabel/datastore/cvat.py

View check run for this annotation

Codecov / codecov/patch

monailabel/datastore/cvat.py#L180

Added line #L180 was not covered by tests

# Return "completed" if all jobs are completed; otherwise "in_progress"
return "completed" if all_completed else "in_progress"

Check warning on line 183 in monailabel/datastore/cvat.py

View check run for this annotation

Codecov / codecov/patch

monailabel/datastore/cvat.py#L183

Added line #L183 was not covered by tests

def upload_to_cvat(self, samples):
project_id = self.get_cvat_project_id(create=True)
Expand Down
Loading