I have a flask web app deployed in heroku. I need to schedule a background task to be scheduled at a specific time. I have tried using the apscheduler module. While it allows to define periodic tasks easily adding them from your application at runtime is what I am looking for.
I tried sharing the same jobstores in apscheduler
import time
from apscheduler.scheduler import Scheduler
from apscheduler.jobstores.shelve_store import ShelveJobStore
sched = Scheduler()
sched.add_jobstore(ShelveJobStore('jobstore.db'), 'shelve')
sched.start()
And from terminal I tried this,
Python 2.7.5 (default, May 12 2013, 12:00:47)
[GCC 4.8.0 20130502 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from apscheduler.scheduler import Scheduler
>>> sc = Scheduler()
>>> sc.add_jobstore('jobstore.db', 'shelve')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dhananjay/git/blast/venv/lib/python2.7/site-packages/apscheduler/scheduler.py", line 168, in add_jobstore
jobstore.load_jobs()
AttributeError: 'str' object has no attribute 'load_jobs'
I have come across this question, while looking for a celery based approach. It talks about the same problem from a django perspective but I can't get it to work with my app (I am completely oblivious to django)
When you tried running it from the terminal, you gave add_jobstore a string as the first parameter, instead of a job store. It expects a job store as the first parameter, see the documentation for more info.
As for scheduling background tasks in Heroku, I would recommend reading the Worker Dynos, Background Jobs and Queueing article on the matter.