Date triggered job continuously gets called

178 views
Skip to first unread message

seyed...@noaa.gov

unread,
Sep 15, 2016, 1:30:39 PM9/15/16
to APScheduler
Hi I have a date triggered job that I schedule using the following
            scheduler.add_job(MY_PROCEDURE, trigger='date', args=[PARAMETERS....],
                              next_run_time=(datetime.now() + timedelta(days=2)))

So the thought is that MY_PROCEDURE gets called 2 days from "now" however it seems to call MY_PROCEDURE on a daily basis.

Am I using this wrong?

Alex Grönholm

unread,
Sep 15, 2016, 1:37:02 PM9/15/16
to apsch...@googlegroups.com

Yes, you're supposed to use the run_date parameter. See the documentation of the date trigger: http://apscheduler.readthedocs.io/en/latest/modules/triggers/date.html#module-apscheduler.triggers.date

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

seyed...@noaa.gov

unread,
Sep 15, 2016, 7:13:11 PM9/15/16
to APScheduler
Got it...so this should work right? (meaning two days after today and only run once)

       scheduler.add_job(MY_PROCEDURE, 'date', run_date=(datetime.now() + timedelta(days=2)), args=[PARAMETERS....])

Alex Grönholm

unread,
Sep 16, 2016, 6:05:57 AM9/16/16
to apsch...@googlegroups.com

Yes.

seyed...@noaa.gov

unread,
Oct 29, 2016, 6:02:52 PM10/29/16
to APScheduler
Thanks Alex, that did the trick. What's strange is is that once in a while I get this error


TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'float'
[2016-10-29 14:52:01,598] ERROR in wsgi: Application exception:
Traceback (most recent call last):
 
File "/var/www/wsgi-scripts/BudgetDB/miniconda3/envs/budgetdb-py34-env/lib/pyt                                                                  hon3.4/site-packages/apscheduler/schedulers/base.py", line 876, in _create_plugi                                                                  n_instance
    plugin_cls
= class_container[alias]
KeyError: 'date'

I am running the scheduler as described in the previous post
  scheduler.add_job(MY_PROCEDURE, 'date', run_date=(datetime.now() + timedelta(days=2)), args=[PARAMETERS....])

Any thoughts?


Alex Grönholm

unread,
Oct 30, 2016, 2:23:55 AM10/30/16
to apsch...@googlegroups.com

That error would suggest that you haven't properly installed APScheduler, so the entry point for "date" is missing. Try instantiating the trigger manually and passing it to add_job() instead of 'date'.

seyed...@noaa.gov

unread,
Oct 30, 2016, 2:36:29 AM10/30/16
to APScheduler
On server startup, I instantiate APScheduler like this

jobstores = {
   
'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite')
}
executors
= {
   
'default': ThreadPoolExecutor(20),
   
'processpool': ProcessPoolExecutor(5)
}
job_defaults
= {
   
'coalesce': False,
   
'max_instances': 3
}
scheduler
= BackgroundScheduler(jobstores=jobstores, executors=executors, job_defaults=job_defaults)
scheduler
.start()

Do I need to make a change to this to make "date" entry point available? Outside of code, I just did a pip install. 

If it's not my initialization above, how do I manually instantiate the trigger? I have checked out https://apscheduler.readthedocs.io/en/latest/modules/triggers/date.html#module-apscheduler.triggers.date
Do I just do trigger = apscheduler.triggers.date?

Alex Grönholm

unread,
Oct 30, 2016, 2:43:42 AM10/30/16
to apsch...@googlegroups.com

Pip installing should have been enough. But to manually instantiate the trigger, simply import the appropriate class (apscheduler.triggers.date.DateTrigger), create an instance of it and pass it to add_job() in place of 'date'.

seyed...@noaa.gov

unread,
Oct 30, 2016, 11:38:39 PM10/30/16
to APScheduler
Awesome, thank you. That worked. 
Reply all
Reply to author
Forward
0 new messages