Can't get jobs to persist

332 views
Skip to first unread message

David Helms

unread,
Mar 17, 2012, 9:43:44 AM3/17/12
to apsch...@googlegroups.com
I can't seem to get jobs to persist.
To test, I'm using the persistent.py example straight out of bitbucket with a print_jobs added to print results.
Run it, ctrl-C, repeat, repeat and I never see any jobs other than the one I just added at runtime.
I've also tried swapping out ShelveJobStore for SQLAlchmeyJobStore, but with the same results.
I must be missing something simple here, got any pointers in the right direction?

"""
This example demonstrates the use of persistent job stores. On each run, it
adds a new alarm that fires after one minute. You can exit the program, restart
it and observe that any previous alarms that have not fired yet are still
active.
"""

from datetime import datetime, timedelta
import sys
import time

from apscheduler.scheduler import Scheduler
from apscheduler.jobstores.shelve_store import ShelveJobStore


def alarm(time):
    sys.stdout.write('Alarm! This alarm was scheduled at %s.\n' % time)


if __name__ == '__main__':
    scheduler = Scheduler()
    scheduler.add_jobstore(ShelveJobStore('example.db'), 'shelve')
    alarm_time = datetime.now() + timedelta(minutes=1)
    scheduler.add_date_job(alarm, alarm_time, name='alarm',
                           jobstore='shelve', args=[datetime.now()])
    sys.stdout.write('To clear the alarms, delete the example.db file.\n')
    sys.stdout.write('Press Ctrl+C to exit\n')
    scheduler.start()
    
    scheduler.print_jobs()

    # This is here to prevent the main thread from exiting so that the
    # scheduler has time to work -- this is rarely necessary in real world
    # applications
    time.sleep(9999)



Output
------
$ python ./persistence.py 
To clear the alarms, delete the example.db file.
Press Ctrl+C to exit
Jobstore default:
    No scheduled jobs
Jobstore shelve:
    alarm (trigger: date[2012-03-17 13:40:43.687639], next run at: 2012-03-17 13:40:43.687639)
^C
$ python ./persistence.py 
To clear the alarms, delete the example.db file.
Press Ctrl+C to exit
Jobstore default:
    No scheduled jobs
Jobstore shelve:
    alarm (trigger: date[2012-03-17 13:40:46.529880], next run at: 2012-03-17 13:40:46.529880)
^C
KeyboardInterrupt
$ python ./persistence.py 
To clear the alarms, delete the example.db file.
Press Ctrl+C to exit
Jobstore default:
    No scheduled jobs
Jobstore shelve:
    alarm (trigger: date[2012-03-17 13:40:49.800349], next run at: 2012-03-17 13:40:49.800349)
^C

Alex Grönholm

unread,
Mar 17, 2012, 5:24:55 PM3/17/12
to apsch...@googlegroups.com
17.03.2012 15:43, David Helms kirjoitti:
I can't seem to get jobs to persist.
To test, I'm using the persistent.py example straight out of bitbucket with a print_jobs added to print results.
Run it, ctrl-C, repeat, repeat and I never see any jobs other than the one I just added at runtime.
I've also tried swapping out ShelveJobStore for SQLAlchmeyJobStore, but with the same results.
I must be missing something simple here, got any pointers in the right direction?
Thanks for pointing this out. I've fixed the persistent example to close the scheduler (and the job store by extension) at ctrl+C.
See https://bitbucket.org/agronholm/apscheduler/src/98b0ab513625/examples/persistent.py for the fixed version.
Reply all
Reply to author
Forward
0 new messages