feat: update finance exchange and source refresh jobs
All checks were successful
CI/CD Pipeline / Quality Gate (push) Successful in 31s
CI/CD Pipeline / Build and Push Images (push) Successful in 34s
CI/CD Pipeline / Internal Notify (push) Successful in 0s
CI/CD Pipeline / Deploy Dev via Compose (push) Successful in 33s

This commit is contained in:
2026-08-09 12:23:36 +02:00
parent 4da56f3823
commit a198f7e960
19 changed files with 266 additions and 52 deletions

View File

@@ -61,6 +61,20 @@ class BackgroundJobModelTest(TestCase):
self.assertEqual(job.result, result)
self.assertIsNotNone(job.completed_at)
def test_complete_clears_previous_failure_details(self):
job = BackgroundJob.objects.create(
task_id=fake.uuid4(),
task_name="test.task",
error="stale error",
traceback="stale traceback",
)
job.complete(result={"processed": 1})
self.assertEqual(job.status, JobStatus.SUCCESS)
self.assertEqual(job.error, "")
self.assertEqual(job.traceback, "")
def test_fail(self):
"""Тест завершения с ошибкой."""
job = BackgroundJob.objects.create(
@@ -288,7 +302,7 @@ class BackgroundJobServiceTest(TestCase):
task_name="apps.other.tasks.task",
meta={"source": "industrial_products"},
)
old_timestamp = timezone.now() - timedelta(hours=3)
old_timestamp = timezone.now() - timedelta(hours=25)
BackgroundJob.objects.filter(
task_id__in=[stale_job.task_id, unrelated_job.task_id]
).update(created_at=old_timestamp, updated_at=timezone.now())
@@ -307,3 +321,37 @@ class BackgroundJobServiceTest(TestCase):
self.assertIn("Stale background job", stale_job.error)
self.assertEqual(fresh_job.status, JobStatus.PENDING)
self.assertEqual(unrelated_job.status, JobStatus.PENDING)
def test_mark_stale_active_jobs_uses_updated_at_for_started_job(self):
job = BackgroundJobService.create_job(
task_id="job-heartbeat",
task_name="apps.parsers.tasks.parse_industrial_products",
meta={"source": "industrial_products"},
)
job.mark_started()
old_timestamp = timezone.now() - timedelta(hours=5)
BackgroundJob.objects.filter(pk=job.pk).update(
started_at=old_timestamp,
updated_at=timezone.now(),
)
updated = BackgroundJobService.mark_stale_active_jobs_failed(
max_age_minutes=240,
task_names={"apps.parsers.tasks.parse_industrial_products"},
meta_sources={"industrial_products"},
)
self.assertEqual(updated, 0)
job.refresh_from_db()
self.assertEqual(job.status, JobStatus.STARTED)
BackgroundJob.objects.filter(pk=job.pk).update(updated_at=old_timestamp)
updated = BackgroundJobService.mark_stale_active_jobs_failed(
max_age_minutes=240,
task_names={"apps.parsers.tasks.parse_industrial_products"},
meta_sources={"industrial_products"},
)
self.assertEqual(updated, 1)
job.refresh_from_db()
self.assertEqual(job.status, JobStatus.FAILURE)