-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(async): Add django-q2 with ORM broker and demo job #161
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| from django.db import migrations | ||
|
|
||
| from firetower.incidents.tasks import SCHEDULES | ||
|
|
||
|
|
||
| def create_schedule(apps, schema_editor): | ||
| Schedule = apps.get_model("django_q", "Schedule") | ||
| schedule_name = "schedule_demo" | ||
| Schedule.objects.get_or_create( | ||
| name=schedule_name, defaults=SCHEDULES[schedule_name] | ||
| ) | ||
|
|
||
|
|
||
| def delete_schedule(apps, schema_editor): | ||
| Schedule = apps.get_model("django_q", "Schedule") | ||
| schedule_name = "schedule_demo" | ||
| Schedule.objects.filter(name=schedule_name).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("incidents", "0014_add_total_downtime"), | ||
| ("django_q", "0018_task_success_index"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(create_schedule, delete_schedule), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from logging import info | ||
|
Check warning on line 1 in src/firetower/incidents/tasks.py
|
||
|
sentry-warden[bot] marked this conversation as resolved.
|
||
|
|
||
| from firetower.incidents.models import Incident | ||
|
|
||
| SCHEDULES = { | ||
| "schedule_demo": { | ||
| "func": "firetower.incidents.tasks.schedule_demo", | ||
| "schedule_type": "I", # Minutes | ||
| "minutes": 5, | ||
| "repeats": -1, # repeat indefinitely | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def schedule_demo() -> None: | ||
| incident = Incident.objects.order_by("-created_at").first() | ||
| if incident: | ||
| info(f"Most recent incident: INC-{incident.id}: {incident.title}") | ||
| else: | ||
| info("No incidents found.") | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migration imports mutable runtime code from tasks module
Medium Severity
The migration imports
SCHEDULESfromfiretower.incidents.tasksat module level, coupling it to mutable runtime code. IfSCHEDULESis ever renamed, restructured, or the"schedule_demo"key is removed, this migration will break on any fresh database. Additionally, importingtasks.pytriggersfrom firetower.incidents.models import Incident, pulling in the live model class rather than the historical version — and any future import-time side effects intasks.pywill also fire during migration. The schedule data (func, schedule_type, minutes, repeats) can be inlined directly in the migration to keep it self-contained.Additional Locations (1)
src/firetower/incidents/migrations/0015_schedule_demo.py#L9-L10Reviewed by Cursor Bugbot for commit eca2c31. Configure here.