-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Restarting rq-scheduler reschedules all periodics #4302
Conversation
interval = kwargs['interval'] | ||
if isinstance(interval, timedelta): | ||
interval = interval.seconds | ||
interval = int(interval.total_seconds()) |
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.
What's the diff between total_seconds()
and seconds
?
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.
timedelta(days=1).seconds == 0
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.
😮
redash/schedule.py
Outdated
def job_id(kwargs): | ||
metadata = kwargs.copy() | ||
if 'func' in metadata: | ||
metadata['func'] = metadata['func'].__name__ |
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.
Can there be a job definition without func
? Also, isn't the func name good enough as a job id?
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.
Not sure what I was thinking with checking for existence in metadata. Anyway, removed in b5237e7.
Hashing all scheduling details (instead of using the job name as an id) allows the scheduler to pick up any changes in schedule and reschedule jobs accordingly. For example - say you want to update the interval
or results_ttl
for a specific job - if you schedule with a job name, it'll be more difficult to pick up those changes and reschedule the job.
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.
How about the job id becomes metadata['func'].__name__:hash
? This way when poking around and seeing a job id it's easy to tell what job it references?
|
||
manager = AppGroup(help="RQ management commands.") | ||
|
||
|
||
@manager.command() | ||
def scheduler(): | ||
schedule_periodic_jobs() | ||
jobs = periodic_job_definitions() | ||
schedule_periodic_jobs(jobs) |
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.
Why not call the function that returns job definitions in schedule_periodic_jobs
?
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.
Purely for testability.
interval = kwargs['interval'] | ||
if isinstance(interval, timedelta): | ||
interval = interval.seconds | ||
interval = int(interval.total_seconds()) |
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.
😮
When
rq-scheduler
restarts, it deletes all existing scheduled jobs and reschedules them. The result of this is that, for example, tasks that should run daily may run more than once a day.Instead of deleting all jobs and rescheduling them, the
scheduler
command should respect previously scheduled jobs and continue their original iterations.