Pthon 3.5上的APScheduler-从作业存储中获取到期作业时出错

时间:2018-11-12 00:07:48

标签: python-3.5 apscheduler

从APScheduler v3.5.3收到以下警告消息,但我找不到原因。

WARNING:apscheduler.scheduler:Error getting due jobs from job store 'default': descriptor 'date' requires a 'datetime.datetime' object but received a 'int'


我遇到此问题的程序最初是为Python 2.7编写的,目前正在为Python 3.5重写。

为APScheduler启用日志记录后,我可以看到该作业已添加到名为“默认”的作业存储中。

INFO:apscheduler.scheduler:Scheduler started
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
INFO:apscheduler.scheduler:Added job "Notifier.gather" to job store "default"
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.scheduler:Next wakeup is due at 2018-11-11 18:33:32.954753-05:00 (in 29.996986 seconds)


大约30秒后,将显示这些消息。它们每10秒重复一次,而不是我预期的30秒。

DEBUG:apscheduler.scheduler:Looking for jobs to run
WARNING:apscheduler.scheduler:Error getting due jobs from job store 'default': descriptor 'date' requires a 'datetime.datetime' object but received a 'int'
DEBUG:apscheduler.scheduler:Next wakeup is due at 2018-11-11 18:33:42.956582-05:00 (in 10.000000 seconds)


我用来设置作业并启动APScheduler的代码。

import atexit
from apscheduler.schedulers.background import BackgroundScheduler

class Notifier(object):

    class NotificationClient(object):

        def __init__(self, gather, timestamp):
            self.gather = gather
            self.timestamp = timestamp

        def run(self):
            self.timestamp = self.gather(self.timestamp)

    def __init__(self):
        self._logger = logging.getLogger(__name__)
        self.notifiers = []

        # Add the jobs here
        self.notifiers.append(self.NotificationClient(self.checkEmails, None))

        # Start the scheduler
        sched = BackgroundScheduler(timezone="America/New_York", daemon=True)
        sched.start()
        sched.add_job(self.gather, 'interval', seconds=30)

        # Shuts down the scheduler when the main program exits
        atexit.register(lambda: sched.shutdown(wait=False))

    def gather(self):
        # client.run() comes from the NotificationClient() class above
        [client.run() for client in self.notifiers]

    #####
    # The function listed in self.notifiers.append()
    def checkEmails(self, lastRun):

        ...code that counts unread emails...

        return lastRun

# Start APScheduler
notifier = Notifier()

0 个答案:

没有答案