How to get status of job using Scheduler?

Question:

I have a scheduled job running on Scheduler library, and I would like to get its status ("Success", "Failed") from python but I can’t find documentation on how to get the status.

Let’s take as an example the following code to use the scheduler :

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)

I can only print the scheduler but I need to print the status of execution, is it possible ?

>>> 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

Please advise

Asked By: selma se

||

Answers:

The job itself has no status message like ("Success", "Failed") because the job does not know if the logic in the scheduled function was "successful".
The user must therefore program the logic himself whether the execution has proceeded as desired.
If you want to know if the job was executed at all, regardless of the result, you can look at the number of executions.
The job has the properties attempts, max_attempts and has_attempts_remaining for this purpose. Here you can find the doc page.
Maybe this example can help you too.

Disclosure: I am one of the authors of the library.

Answered By: jpotyka
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.