How To Interpret List Of Jobs Returned From Get_jobs In Apscheduler?
Solution 1:
OK, thanks to a previously asked question on the APScheduler Google group, I have a solution!
The details have to be accessed through the fields, as I thought. The key to get the information from the individual field is to convert the field value to a string.
Here is an example which works:
schedules = []
forjobinself.scheduler.get_jobs():
jobdict = {}
forfin job.trigger.fields:
curval = str(f)
jobdict[f.name] = curval
schedules.append(jobdict)
For a schedule with one job added as:
new_job = self.scheduler.add_job(jobfunc,'cron', second='*/5', args=["second"])
The resulting list comes out like this:
[{'week': '*', 'hour': '*', 'day_of_week': '*', 'month': '*', 'second': '*/5', 'year': '*', 'day': '*', 'minute': '*'}]
Solution 2:
APScheduler .get_jobs()
method returns a list of job instances.
For example, you can print information about all currently scheduled jobs with something like the following:
for job in scheduler.get_jobs():
print("name: %s, trigger: %s, next run: %s, handler: %s" % (
job.name, job.trigger, job.next_run_time, job.func))
Note that job names can repeat across different jobs.
You can find here the API reference for the job
class. It doesn't explicitly list the job class members, but they match the variables in kwargs.
Solution 3:
Putting this here for anyone who is trying to find different attrs of their Job object.
Since the object doesn't utilize __dict__
use __slots__
instead. This will show you all the different attributes of the Job Object just as __dict__
would.
>>> scheduler.get_jobs()[0].__slots__
('_scheduler', '_jobstore_alias', 'id', 'trigger', 'executor', 'func', 'func_ref', 'args', 'kwargs', 'name', 'misfire_grace_time', 'coalesce', 'max_instances', 'next_run_time', '__weakref__')
Then with this information you can then retrieve the attrs
>>> scheduler.get_jobs()[0].trigger
<IntervalTrigger (interval=datetime.timedelta(seconds=1200), start_date='2021-08-06 10:01:19 CDT', timezone='America/Chicago')>
>>> scheduler.get_jobs()[0].max_instances
1
Post a Comment for "How To Interpret List Of Jobs Returned From Get_jobs In Apscheduler?"