Skip to content

[BUG] Job_queue is skipping job if timezone is not provided for job.run_daily #1693

@Andrej730

Description

@Andrej730

For example, my local timezone is +3 UTC and I want to run job every working day at 23:00 UTC.

launch_time.tzinfo is None so it's expected to be interpreted as 23:00 UTC.

launch_time = dtm.time(hour=23)
job = job_queue.run_daily(run_once, launch_time,
                          days=(0, 1, 3, 4))

Since launch_time.tzinfo was None, job.tzinfo is also equals None because of the following code from JobQueue.run_daily

job = Job(callback,
interval=datetime.timedelta(days=1),
repeat=True,
days=days,
tzinfo=time.tzinfo,
context=context,
name=name,
job_queue=self)

Let's assume now is 23:00 UTC Friday.

The following code from JobQueue.tick won't run the job because

  1. datetime.datetime.now(None) returns local time and local time now is 02:00 Saturday.
  2. then datetime.datetime.now(job.tzinfo).date().weekday() will return 5
  3. any(day == current_week_day for day in job.days) will return False because we're looking for (0, 1, 3, 4)
    So job won't be run until 23:00 UTC Sunday.
    if job.enabled:
    try:
    current_week_day = datetime.datetime.now(job.tzinfo).date().weekday()
    if any(day == current_week_day for day in job.days):
    self.logger.debug('Running job %s', job.name)
    job.run(self._dispatcher)

And one more thing - when #1685 will be merged, in the described case Job.next_t will be returning local time when utc time is expected:

    @property
    def next_t(self):
        return datetime.datetime.fromtimestamp(self._next_t, self.tzinfo) if self._next_t else None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions