Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG + REFACTOR] Change behavior of JobQueue.run_monthly #2627

@Bibo-Joshi

Description

@Bibo-Joshi

Steps to reproduce

  1. job_queue.run_monthly(day=30, day_is_strict=False)

Expected behaviour

Runs on 30th day of each month excluding Feb + on Feb 28th/29th

Actual behaviour

Runs on 30th and 31st day of each month excluding Feb + on Feb 28th/29th

This happens because I didn't pay enough attention when writing this:

else:
trigger = OrTrigger(
[
CronTrigger(
day=day,
hour=when.hour,
minute=when.minute,
second=when.second,
timezone=when.tzinfo,
**job_kwargs,
),
CronTrigger(
day='last',
hour=when.hour,
minute=when.minute,
second=when.second,
timezone=when.tzinfo or self.scheduler.timezone,
**job_kwargs,
),
]
)

However, the use case of day_is_strict is mainly "run on the last day of the month". I therefore suggest to just drop the parameter and instead allow to pass day='last' or day=-1 (I like this one better) to indicate that you want to run the job on the last day of the month.
The use case described above can still be achieved with run_custom.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions