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

Find better pattern for scheduling first run of Task #38

Open
joshuadavidthomas opened this issue May 8, 2024 · 1 comment
Open

Find better pattern for scheduling first run of Task #38

joshuadavidthomas opened this issue May 8, 2024 · 1 comment
Labels
🏋️ improvement Enhancements or optimizations to existing functionality 🧁 needs baking Requires more time for consideration or development before further action

Comments

@joshuadavidthomas
Copy link
Member

I'm trying to migrate an internal application to use django-q-registry. I have this task that needs to run periodically:

from __future__ import annotations

from django_q.models import Schedule
from django_q_registry import register_task

from assets.employees.models import Supervisor


@register_task(
    name="Send quarterly Asset Reports to all Supervisors",
    schedule_type=Schedule.QUARTERLY,
)
def send_asset_reports():
    for supervisor in Supervisor.objects.all():
        supervisor.send_assets_report()

It exists in the database as an unmanaged Schedule, with the next run date a couple months in the future. I don't want to pass next_run to the register_task decorator because when I remove it the internals of this library would consider it a 'new' task and remove it and recreate it with the next run time being right now.

I don't want it to run right now, I'd like to temporarily pass in the initial time to run, then have setup_periodic_tasks run to create it with this initial time set as the next run time, and then finally remove the initial time without the library thinking it's a completely new Task.

@joshuadavidthomas joshuadavidthomas added 🧁 needs baking Requires more time for consideration or development before further action 🏋️ improvement Enhancements or optimizations to existing functionality labels May 8, 2024
@joshuadavidthomas
Copy link
Member Author

First draft thought would be to add an initial_run field to the Task model that allows for setting the Schedule.next_run field on creation that can be subsequently removed in another deployment. We would need to take care to make sure it does not affect a Task's equality or hashing so that to this library it would appear to be the same and not clean it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏋️ improvement Enhancements or optimizations to existing functionality 🧁 needs baking Requires more time for consideration or development before further action
Projects
None yet
Development

No branches or pull requests

1 participant