agronholm / apscheduler

Task scheduling library for Python
MIT License
5.98k stars 694 forks source link

misfire_grace_time being passed but not used? #863

Closed nrathaus closed 2 months ago

nrathaus commented 5 months ago

Things to check first

Version

4.0.0a4

What happened?

While running the below script you would expect the logging to provide indication that a misfire_grace_time is being passed, it shows it as not:

INFO:apscheduler._schedulers.sync:Scheduler started
INFO:apscheduler._schedulers.sync:Added new schedule (task=Task(id='__main__:some_function', 
func='__main__:some_function', job_executor='threadpool', max_running_jobs=None, misfire_grace_time=None), 
trigger=IntervalTrigger(seconds=5, start_time='2024-02-13 14:34:29.616509+02:00')); next run time at 2024-02-13 
14:34:29.616509+02:00

How can we reproduce the bug?

import logging

import datetime
from apscheduler.triggers.interval import IntervalTrigger
from apscheduler import Scheduler

def some_function():
    print("some_function run")

logging.basicConfig(level=logging.INFO)
SCHEDULER = Scheduler()
SCHEDULER.start_in_background()

trigger = IntervalTrigger(seconds=5)

SCHEDULER.add_schedule(
    some_function,
    trigger=trigger,
    id="some_function",
    # Allow for users to give incorrect date - within a 1hr scope
    misfire_grace_time=datetime.timedelta(hours=1),
)
agronholm commented 5 months ago

This sounds like your problem is with misfire_grace_time not showing up in the logging output? I should mention that the fact that the task= shows so many details is an oversight – it should just show the task ID.

nrathaus commented 5 months ago

While it might be an oversight that the data is shown, what isn't making sense is that the value is None while it was provided during the Scheduler setup

injust commented 2 months ago

https://github.com/agronholm/apscheduler/pull/908#issuecomment-2106171049

It's not supposed to be added to the task, but only the schedule. If one wants to have a default misfire_grace_time for the task, they can explicitly configure the task that way.

Which means everything is working as intended and there is no bug.

The log is showing the task's misfire_grace_time (which is unset and is correctly logged as None), not the scheduler's misfire_grace_time (which is set, but isn't logged).

agronholm commented 2 months ago

Ok, where is the wrong misfire_grace_time logged?

agronholm commented 2 months ago

Oh right, there's a provided MWE. Let me check.

agronholm commented 2 months ago

Alright, I see where the confusion stems from. I should fix the logging to only log the task ID, not the entire Task instance. So in a way, there was indeed a bug.