如何使用调度程序获取作业状态?

How to get status of job using Scheduler?

我在 Scheduler 图书馆有一个预定的工作 运行,我想从 python 获得它的状态 ("Success", "Failed") 但我找不到关于如何获取状态。

让我们以下面的代码为例来使用调度程序:

import datetime as dt
import time

from scheduler import Scheduler

import scheduler.trigger as trigger

def foo():

    print("foo")

schedule = Scheduler()
schedule.minutely(dt.time(second=15), foo)
while True:  

    schedule.exec_jobs()

    time.sleep(1)

我只能打印调度程序,但我需要打印执行状态,可以吗?

>>> print(schedule)  
max_exec=inf, tzinfo=None, priority_function=linear_priority_function, #jobs=9

type     function         due at                 due in      attempts weight
-------- ---------------- ------------------- --------- ------------- ------
MINUTELY foo(..)          2022-03-30 00:37:15   0:00:14         0/inf      1

请指教

作业本身没有(“成功”、“失败”)之类的状态消息,因为作业不知道预定函数中的逻辑是否“成功”。 因此,用户必须自己对逻辑进行编程,无论执行是否按预期进行。 如果你想知道作业是否被执行,不管结果如何,你可以查看执行次数。 为此,作业具有属性 attemptsmax_attemptshas_attempts_remainingHere 您可以找到文档页面。 也许这篇 example 也能帮到你。

披露:我是图书馆的作者之一。