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

Reset some rq meta fields when retrying rq job #8719

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion cvat/apps/dataset_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from cvat.apps.engine.log import ServerLogManager
from cvat.apps.engine.models import Job, Project, Task
from cvat.apps.engine.utils import get_rq_lock_by_user
from cvat.apps.engine.rq_job_handler import RQMeta

from .formats.registry import EXPORT_FORMATS, IMPORT_FORMATS
from .util import (
Expand Down Expand Up @@ -84,7 +85,7 @@ def _patched_retry(*_1, **_2):
*current_rq_job.args,
**current_rq_job.kwargs,
job_id=current_rq_job.id,
meta=current_rq_job.meta,
meta=RQMeta.reset_meta_on_retry(current_rq_job.meta),
job_ttl=current_rq_job.ttl,
job_result_ttl=current_rq_job.result_ttl,
job_description=current_rq_job.description,
Expand Down
21 changes: 20 additions & 1 deletion cvat/apps/engine/rq_job_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@

import attrs

from typing import Optional, Union
from typing import Optional, Union, Any
from uuid import UUID
from rq.job import Job as RQJob

from .models import RequestAction, RequestTarget, RequestSubresource

class RQMeta:
@staticmethod
def get_resettable_fields() -> list[RQJobMetaField]:
"""Return a list of fields that must be reset on retry"""
return [
RQJobMetaField.FORMATTED_EXCEPTION,
RQJobMetaField.PROGRESS,
RQJobMetaField.TASK_PROGRESS,
RQJobMetaField.STATUS
]

@classmethod
def reset_meta_on_retry(cls, meta_to_update: dict[RQJobMetaField, Any]) -> dict[RQJobMetaField, Any]:
resettable_fields = cls.get_resettable_fields()

return {
k: v for k, v in meta_to_update.items() if k not in resettable_fields
}

class RQJobMetaField:
# common fields
FORMATTED_EXCEPTION = "formatted_exception"
Expand Down
Loading