An easy job scheduling interface for flask projects.
Project description
An easy job scheduling interface for flask projects.
Install
pip install flask_jobs
Schedule a job to run ASAP
from flask_jobs import AddJob def Callback(*args, **kwargs): print('The Callback function was called with args=', args, ' and kwargs=', kwargs) newJob = AddJob( func=Callback, a=(1, 'two', {'three': '4'}), k={'key': 'word'}, ) # The job will be run in a separate thread ASAP. # You can check the status of your job print('newJob['status']=', newJob['status']) # will return 'pending' or 'complete' or 'error' >> newJob['status']= complete
Schedule a job to happen once in the future
from flask_jobs import ScheduleJob import datetime def Callback(*args, **kwargs): print('The Callback function was called with args=', args, ' and kwargs=', kwargs) newJob = ScheduleJob( dt=datetime.datetime.utcnow() + datetime.timedelta(seconds=10), # all datetimes are in UTC func=Callback, a=(1, 'two', {'three': '4'}), k={'key': 'word'}, ) # The job will be run in a separate thread ASAP. # You can check the status of your job print('newJob['status']=', newJob['status']) # will return 'pending' or 'complete' or 'error' >> newJob['status']= pending # wait 10 seconds print('newJob['status']=', newJob['status']) >> newJob['status']= complete
Schedule a job to repeat indefinitely
from flask_jobs import RepeatJob def Callback(*args, **kwargs): print('The Callback function was called with args=', args, ' and kwargs=', kwargs) def CalcNextRepeat(): # should repeat every 30 seconds # this function should return the next datetime that this job should be run nextDT = datetime.datetime.utcnow().replace(microsecond=0) if nextDT.second < 30: nextDT = nextDT.replace(second=30) else: nextDT += datetime.timedelta(minutes=1) nextDT = nextDT.replace(second=0) return nextDT RepeatJob( repeatCallback=CalcNextRepeat, func=JobCallback, args=('Repeating',), kwargs={'key': 'val'} ) # All jobs are persistent. Even if you restart your server.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_jobs-0.0.1.tar.gz
(3.9 kB
view hashes)
Built Distribution
Close
Hashes for flask_jobs-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19692d45ff41f25978b521d249172177a9a95250edd9eefd62c3bfa87cb7fb8c |
|
MD5 | 17380020155888a5fa7b1fde8f441de8 |
|
BLAKE2b-256 | bf2cc9904fe4c5df5c5a3c644093eb8d31f37dcfa8f0fcce938608cc4ef187fb |