hot to get status and hour / minute settinng of cron type job

536 views
Skip to first unread message

bovic

unread,
Oct 31, 2016, 10:02:40 AM10/31/16
to APScheduler
HI there,

i am just starting with flask / python and having difficulties to display the details of a job.

I want to display the following for cron style jobs:
* Job Name (or job id)
* hour
* minute
* status (paused, active or currently running)

I tried very unsuccessfully:
    job_list = '<h3>Job Info</h3><br/>'
   
for job in scheduler.get_jobs():
        job_list
+= job.name + job.trigger['hour'] + job.trigger['minute'] + job.status

i think it's just a syntax problem with the hour/minute values, i haven't figured out how to get the status (Paused|Running|?)

I am glad for every hint here.

Alex Grönholm

unread,
Oct 31, 2016, 1:35:43 PM10/31/16
to apsch...@googlegroups.com

You can't concatenate arbitrary types in Python. Use string formatting instead: https://docs.python.org/3.5/library/stdtypes.html#printf-style-string-formatting

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bovic

unread,
Oct 31, 2016, 11:11:00 PM10/31/16
to APScheduler
thanks!

turns out i was also lacking the concept of fields ... it works now :)

    joblist = ''
   
for job in scheduler.get_jobs():
        job
=  scheduler.get_job(job.id)
       
for f in job.trigger.fields:
           
if f.name == 'hour':
                hour
= f
           
if f.name == 'minute':
                minute
= f
        joblist
+= '%(jobname)s : %(jobhour)s:%(jobminute)s' % {"jobname": job.name, "jobhour": hour, "jobminute": minute}
   
return joblist

Alex Grönholm

unread,
Nov 1, 2016, 2:16:00 AM11/1/16
to apsch...@googlegroups.com

With this code, your jobs will be concatenated to one string without any delimiters and it looks bad.

How about this instead?

joblist = []

joblist.append('{job.name}: {job.hour}:{job.minute}'.format(job=job))

return '\n'.join(joblist)

bovic

unread,
Nov 1, 2016, 9:38:36 AM11/1/16
to APScheduler
Hi Alex, this is neat, thank you!

this is how I innitialize my job:

from datetime import datetime, timedelta
class Config(object):
JOBS = [
{
'id': 'cron_coffee',
'func': 'jobs:make_coffee',
'trigger': 'cron',
'hour': '7',
'minute': '1',
},
]
SCHEDULER_VIEWS_ENABLED = True
is it possible to "start" the job as "paused"? I think it will be more secure, so i will not burn down my kitchen.

cheers and thanks!

Basya Perlman

unread,
Jul 31, 2017, 7:05:15 AM7/31/17
to APScheduler
Hi.

I am also having trouble interpreting the output of get_jobs.  I am trying suggestions from here and still have some questions and problems.

First of all, when I try this code: 
On Tuesday, November 1, 2016 at 8:16:00 AM UTC+2, Alex Grönholm wrote:

With this code, your jobs will be concatenated to one string without any delimiters and it looks bad.

How about this instead?

joblist = []

joblist.append('{job.name}: {job.hour}:{job.minute}'.format(job=job))

return '\n'.join(joblist)



I get an error:

AttributeError: 'Job' object has no attribute 'hour'

From looking at the data structure, this error makes sense, as hour, minute, second, etc. are in "fields".

Yet the original poster was happy with this response.  So I am clearly misunderstanding something.

Could you explain how to use this?

Also, in "bovic"'s original code, he does:
    for job in scheduler.get_jobs():
        job
=  scheduler.get_job(job.id)
Why is the second line necessary?  Isn't each job in the for loop a job just as the one returned from get_jobs?  It looks as though he is getting the list of jobs, looping through it, and then taking the id from job to call get_job to set "job" to the same thing it referred to already.  Am I missing something, or is this code redundant?

Thank you.
Batya 
Reply all
Reply to author
Forward
0 new messages