feat: update finance exchange and source refresh jobs
This commit is contained in:
@@ -169,12 +169,16 @@ class BackgroundJob(TimestampMixin, models.Model):
|
||||
self.status = JobStatus.SUCCESS
|
||||
self.progress = 100
|
||||
self.result = result
|
||||
self.error = ""
|
||||
self.traceback = ""
|
||||
self.completed_at = timezone.now()
|
||||
self.save(
|
||||
update_fields=[
|
||||
"status",
|
||||
"progress",
|
||||
"result",
|
||||
"error",
|
||||
"traceback",
|
||||
"completed_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
@@ -752,21 +752,21 @@ class BackgroundJobService(BaseReadOnlyService):
|
||||
cls,
|
||||
*,
|
||||
max_age_minutes: int,
|
||||
pending_max_age_minutes: int = 24 * 60,
|
||||
task_names: set[str] | None = None,
|
||||
meta_sources: set[str] | None = None,
|
||||
) -> int:
|
||||
"""Mark old active jobs as failed after worker restarts or hard kills."""
|
||||
from apps.core.models import JobStatus
|
||||
|
||||
cutoff = timezone.now() - timedelta(minutes=max_age_minutes)
|
||||
queryset = (
|
||||
cls.get_queryset()
|
||||
.filter(
|
||||
status__in=[JobStatus.PENDING, JobStatus.STARTED, JobStatus.RETRY],
|
||||
)
|
||||
.filter(
|
||||
Q(started_at__isnull=False, started_at__lt=cutoff)
|
||||
| Q(started_at__isnull=True, created_at__lt=cutoff)
|
||||
now = timezone.now()
|
||||
cutoff = now - timedelta(minutes=max_age_minutes)
|
||||
pending_cutoff = now - timedelta(minutes=pending_max_age_minutes)
|
||||
queryset = cls.get_queryset().filter(
|
||||
Q(status=JobStatus.PENDING, created_at__lt=pending_cutoff)
|
||||
| Q(
|
||||
status__in=[JobStatus.STARTED, JobStatus.RETRY],
|
||||
updated_at__lt=cutoff,
|
||||
)
|
||||
)
|
||||
if task_names:
|
||||
|
||||
Reference in New Issue
Block a user