feat: enable requested source collection schedules
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Failing after 6s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Has been skipped
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Failing after 6s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Has been skipped
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
This commit is contained in:
@@ -280,15 +280,20 @@ def test_new_schedule_seed_always_disabled(module_name):
|
||||
from django_celery_beat.models import PeriodicTask
|
||||
|
||||
module = importlib.import_module(module_name)
|
||||
module.seed(apps, None)
|
||||
tasks = PeriodicTask.objects.filter(
|
||||
task__in=[
|
||||
"parsers.fssp_enforcement_proceedings.refresh",
|
||||
seeded_tasks = {
|
||||
"apps.parsers.migrations.0043_fssp_disabled_schedule": [
|
||||
"parsers.fssp_enforcement_proceedings.refresh"
|
||||
],
|
||||
"apps.parsers.migrations.0045_checko_disabled_schedules": [
|
||||
"parsers.checko_leasing.refresh",
|
||||
"parsers.checko_messages.refresh",
|
||||
"parsers.checko_licenses.refresh",
|
||||
"parsers.stock_exchange_activity.refresh",
|
||||
]
|
||||
)
|
||||
],
|
||||
"apps.parsers.migrations.0047_exchange_disabled_schedule": [
|
||||
"parsers.stock_exchange_activity.refresh"
|
||||
],
|
||||
}
|
||||
module.seed(apps, None)
|
||||
tasks = PeriodicTask.objects.filter(task__in=seeded_tasks[module_name])
|
||||
assert tasks.exists()
|
||||
assert not tasks.filter(enabled=True).exists()
|
||||
|
||||
@@ -10,6 +10,17 @@ schedule_migration = importlib.import_module(
|
||||
|
||||
|
||||
class DefaultParserScheduleTest(TestCase):
|
||||
def setUp(self):
|
||||
# Historical seed migrations may already have installed these fixtures.
|
||||
PeriodicTask.objects.filter(
|
||||
name__in=[
|
||||
"parser:inspections:weekly-saturday-msk",
|
||||
"parse-inspections-weekly",
|
||||
"parser:sync_inspections:weekly-saturday-msk",
|
||||
"parser:fns_financial:weekly-saturday-msk",
|
||||
]
|
||||
).delete()
|
||||
|
||||
def test_inspections_have_one_canonical_sync_schedule(self):
|
||||
crontab = CrontabSchedule.objects.create(
|
||||
minute="0",
|
||||
@@ -102,3 +113,51 @@ class DefaultParserScheduleTest(TestCase):
|
||||
self.assertTrue(task.enabled)
|
||||
self.assertIsNotNone(task.crontab_id)
|
||||
self.assertIsNone(task.interval_id)
|
||||
|
||||
|
||||
class RequestedSourceScheduleTest(TestCase):
|
||||
def test_forward_migration_enables_exact_five_sources_idempotently(self):
|
||||
for name in (
|
||||
"0043_fssp_disabled_schedule",
|
||||
"0045_checko_disabled_schedules",
|
||||
"0047_exchange_disabled_schedule",
|
||||
):
|
||||
importlib.import_module(f"apps.parsers.migrations.{name}").seed(apps, None)
|
||||
other = PeriodicTask.objects.create(
|
||||
name="unrelated-disabled-schedule",
|
||||
task="synthetic.unrelated",
|
||||
interval=IntervalSchedule.objects.first(),
|
||||
enabled=False,
|
||||
)
|
||||
migration = importlib.import_module(
|
||||
"apps.parsers.migrations.0048_enable_requested_source_schedules"
|
||||
)
|
||||
migration.enable_schedules(apps, None)
|
||||
migration.enable_schedules(apps, None)
|
||||
expected = {
|
||||
"parser:fssp-enforcement-proceedings:daily": (
|
||||
"parsers.fssp_enforcement_proceedings.refresh",
|
||||
1,
|
||||
),
|
||||
"parser:stock-exchange-activity:daily": (
|
||||
"parsers.stock_exchange_activity.refresh",
|
||||
1,
|
||||
),
|
||||
"parser:checko-leasing:monthly": ("parsers.checko_leasing.refresh", 30),
|
||||
"parser:checko-messages:monthly": ("parsers.checko_messages.refresh", 30),
|
||||
"parser:checko-licenses:monthly": ("parsers.checko_licenses.refresh", 30),
|
||||
}
|
||||
tasks = list(
|
||||
PeriodicTask.objects.filter(name__in=expected).select_related("interval")
|
||||
)
|
||||
assert len(tasks) == 5
|
||||
for task in tasks:
|
||||
assert task.enabled
|
||||
assert (task.task, task.interval.every) == expected[task.name]
|
||||
assert task.interval.period == "days"
|
||||
assert task.args == "[]" and task.kwargs == "{}"
|
||||
other.refresh_from_db()
|
||||
assert not other.enabled
|
||||
migration.disable_schedules(apps, None)
|
||||
assert not PeriodicTask.objects.filter(name__in=expected, enabled=True).exists()
|
||||
assert PeriodicTask.objects.filter(name__in=expected).count() == 5
|
||||
|
||||
Reference in New Issue
Block a user