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

Restarting rq-scheduler reschedules all periodics #4302

Merged
merged 9 commits into from
Nov 11, 2019

Conversation

rauchy
Copy link
Contributor

@rauchy rauchy commented Nov 7, 2019

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.

@rauchy rauchy requested a review from arikfr November 7, 2019 14:10
interval = kwargs['interval']
if isinstance(interval, timedelta):
interval = interval.seconds
interval = int(interval.total_seconds())
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

def job_id(kwargs):
metadata = kwargs.copy()
if 'func' in metadata:
metadata['func'] = metadata['func'].__name__
Copy link
Member

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?

Copy link
Contributor Author

@rauchy rauchy Nov 10, 2019

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.

Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely for testability.

@rauchy rauchy requested a review from arikfr November 11, 2019 06:58
interval = kwargs['interval']
if isinstance(interval, timedelta):
interval = interval.seconds
interval = int(interval.total_seconds())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

@rauchy rauchy merged commit e0e94d7 into master Nov 11, 2019
@rauchy rauchy deleted the resume-schedule-after-restart branch November 11, 2019 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants