Issues

Issue #34 invalid

Can't get jobs running

andrea_crotti
created an issue

So I'm trying out apscheduler and I think it's great, but I don't get the events running for some reason.. I'm using APScheduler-2.1.0-py2.7 on Archlinux 64 bits.

Here below is the simple script I'm trying, when I run it I see that the job is actually created but it looks like nothing is ever run:

$ python simple.py [<Job (name=partial, trigger=<SimpleTrigger (run_date=datetime.datetime(2013, 3, 19, 12, 29, 10, 845871))>)>]

All it should do is to create a couchdb database or and write a document in it, but I don't get the entry in the db and I don't get any error either.

Wait=True also seems to do nothing, but even adding a while True: pass

right after doesn't seem to have any effect.. Any idea why the job is not actually run?

from datetime import datetime, timedelta
from apscheduler.scheduler import Scheduler, EVENT_JOB_ERROR, EVENT_JOB_EXECUTED
from functools import partial

from couchdbkit import Server

sched = Scheduler()


def write_to_db(db_name, doc):
    s = Server()
    s.get_or_create_db(db_name)
    print("Saving document %s" % str(doc))
    s.save_doc(doc)
    raise AssertionError


def my_listener(event):
    if event.exception:
        print("Running the job crashed")
    else:
        print("Everything worked fine")


if __name__ == '__main__':
    sched.add_listener(my_listener, EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
    in_2_minutes = datetime.utcnow() + timedelta(seconds=2)
    sched.add_date_job(partial(write_to_db, 'test_db', {'x': 10}), in_2_minutes)

    sched.start()
    sched.shutdown(wait=True)

Comments (1)

  1. Alex Grönholm repo owner

    The job does not run because you're shutting down the scheduler right after starting it. Next time, ask on IRC or the Google group, don't create a new issue!

  2. Log in to comment