-
Notifications
You must be signed in to change notification settings - Fork 487
Dry-run Database Scheduler #968
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 |
|---|---|---|
|
|
@@ -542,3 +542,39 @@ def schedule(self): | |
| repr(entry) for entry in self._schedule.values()), | ||
| ) | ||
| return self._schedule | ||
|
|
||
|
|
||
| class DryRunDatabaseScheduler(DatabaseScheduler): | ||
| """ | ||
| DatabaseScheduler in dry-run mode. | ||
|
|
||
| The Scheduler reads Periodic Tasks from the database but does not execute them, | ||
| only logging when they would have been triggered. | ||
| Useful in environments where tasks should not actually run, but the scheduler | ||
| must remain operational. | ||
| """ | ||
|
|
||
| def apply_entry(self, entry, producer=None): | ||
| """ | ||
| Overwritten method to log the triggered tasks instead of actually running them. | ||
| """ | ||
| debug( | ||
| 'Dry-run mode: Skipping task %s %s %s', | ||
| entry.task, | ||
| entry.args, | ||
| entry.kwargs | ||
| ) | ||
|
Comment on lines
+547
to
+566
|
||
|
|
||
| def sync(self): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @auvipy , thanks for this suggestion. I understand that we are skipping the metadata update in dry-run mode since the task wasn't actually executed. But don't we need to store the attempt of execution to prevent breaking the scheduler loop? For an hourly task, for example, don't we want to persist the execution attempt? If not, it will only be stored in memory, right? Any refresh of the tasks in the event loop will confuse the scheduler. |
||
| """ | ||
| Override sync to avoid persisting execution metadata in dry-run mode. | ||
|
|
||
| In DatabaseScheduler, sync() saves dirty entries (including updated | ||
| last_run_at and total_run_count) back to the database. For a dry-run | ||
| scheduler this would be misleading, since tasks are never actually run. | ||
|
|
||
| By overriding sync as a no-op, we ensure that dry-run operation does not | ||
| modify PeriodicTask records in the database while still allowing the | ||
| scheduler machinery to operate normally. | ||
| """ | ||
| debug('Dry-run mode: Skipping database sync of scheduled tasks.') | ||
|
Comment on lines
+568
to
+580
|
||
Uh oh!
There was an error while loading. Please reload this page.