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

Missed jobs although misfire_grace_time is set #146

Closed
maxnoe opened this issue May 30, 2016 · 20 comments
Closed

Missed jobs although misfire_grace_time is set #146

maxnoe opened this issue May 30, 2016 · 20 comments
Labels

Comments

@maxnoe
Copy link

maxnoe commented May 30, 2016

Using the apscheduler together with an sqlite datebase and a daily cron at 11:00 I get missed run times by 1 or two minutes although I set the misfire gracetime to 15 Minutes:

self.scheduler = BackgroundScheduler(
    logger=log,
    jobstores={'sqlite': SQLAlchemyJobStore(url='sqlite:///clients.sqlite'    )},
    misfire_grace_time=15*60, 
)
Run time of job "send_menu (trigger: cron[day_of_week='mon-fri', hour='11'], next run 
at: 2016-05-31 11:00:00 CEST)" was missed by 0:00:01.51075
Run time of job "send_menu (trigger: cron[day_of_week='mon-fri', hour='11'], next run 
at: 2016-05-31 11:00:00 CEST)" was missed by 0:00:01.562219
...
@agronholm
Copy link
Owner

You're right – the global value isn't being applied! I will look into this ASAP.

@agronholm
Copy link
Owner

As a workaround, give the misfire grace time value to each job individually. That at least works.

@agronholm
Copy link
Owner

Ah, this is not a bug but a user error. The misfire_grace_time setting must be passed in the job_defaults argument, like so:

self.scheduler = BackgroundScheduler(
    logger=log,
    jobstores={'sqlite': SQLAlchemyJobStore(url='sqlite:///clients.sqlite'    )},
    job_defaults={'misfire_grace_time': 15*60},
)

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

Ah, I understand. Thanks for the fast reply. But shouldn't then BackgroundScheduler.__init__ complain about an unused or unkown keyword argument? This would be really helpful.

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

Oh, and also the message that is generated on the miss seems to be a print not a log.

@agronholm
Copy link
Owner

Yes, the configuration system was initially thought out differently. I intend to replace it in the next major version with something simpler.

@agronholm
Copy link
Owner

Wait, what? No, logger.warning() is used to emit the message.

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

Strange, my logger instance has a FileHandler and a StreamHandler and the message is not in the logfile.

@agronholm
Copy link
Owner

Are you using a process pool executor?

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

I use it like I posted, which should be threading, right?

@agronholm
Copy link
Owner

Right. But there is no print anywhere as you can see: https://github.com/agronholm/apscheduler/blob/master/apscheduler/executors/base.py#L120

@agronholm
Copy link
Owner

Can I see your logging configuration?

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

log = logging.getLogger('mensabot')
log.setLevel(logging.INFO)
formatter = logging.Formatter(
    fmt='%(asctime)s|%(levelname)s|%(name)s|%(message)s',
    datefmt='%Y-%m-%d %H:%M:%S',
)
stream_handler = logging.StreamHandler()
file_handler = logging.FileHandler('mensabot.log', encoding='utf-8')
stream_handler.setFormatter(formatter)
file_handler.setFormatter(formatter)
log.addHandler(stream_handler)
log.addHandler(file_handler)

@agronholm
Copy link
Owner

You're only configuring logging for the "mensabot" logger. There is no configuration here that would match "apscheduler".

@maxnoe
Copy link
Author

maxnoe commented May 30, 2016

I thought passing the logger instance to BackgroundScheduler would make it use that logger. Why else should I pass a logger to the scheduler instance?

From the docs:

Parameters:

  • logger (str|logging.Logger) – logger to use for the scheduler’s logging (defaults to apscheduler.scheduler)

@agronholm
Copy link
Owner

Ah, sorry again. Multitasking is clearly not doing me any good :(
I wonder if run_job() is being passed the correct logger name. If not, that's on me.

@agronholm
Copy link
Owner

Got it. The logger parameter only affects scheduler logging, not executor logging. Those are still logged to apscheduler.executors.

@agronholm
Copy link
Owner

But if I make the executors share the logger now, it will break things for people who expect this :(

@maxnoe
Copy link
Author

maxnoe commented May 31, 2016

Can I somehow set the logger of the executor?

@agronholm
Copy link
Owner

Yes, it's the _logger attribute of the executor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants