An easy job scheduling interface for flask projects.
Install
pip install flask_jobs
Example Flask Project
import datetime
import time
from flask import Flask, render_template, redirect
from flask_jobs import JobScheduler
app = Flask('JobApp')
jobs = JobScheduler(
app,
SERVER_HOST_URL='https://mysite.com/', # only required for linux
deleteOldJobs=False,# whether to keep old jobs in the database
)
def Callback(*a, **k):
print('Callback(', a, k)
@app.route('/')
def Index():
return render_template(
'index.html',
jobs=jobs.GetJobs(),
utcnow=datetime.datetime.utcnow(),
)
@app.route('/add_now_job')
def NowJob():
# Schedule a job to happen ASAP
jobs.AddJob(
func=Callback,
args=('Now Job now={}'.format(datetime.datetime.utcnow()),),
kwargs={'one': 'won', 'two': 'too'},
name='Now Job at {}'.format(time.asctime())
)
return redirect('/')
@app.route('/add_later_job')
def LaterJob():
# Schedule a job to happen once in the future
dt = datetime.datetime.utcnow() + datetime.timedelta(seconds=5)
jobs.ScheduleJob(
dt=dt,
func=Callback,
args=('ScheduleJob now={}, dt={}'.format(
datetime.datetime.utcnow(),
dt
),),
kwargs={'one': 'won', 'two': 'too'},
name='ScheduleJob Job at {}'.format(time.asctime())
)
return redirect('/')
@app.route('/add_repeat_job')
def Repeat():
# Schedule a job to repeat at the given interval
dt = datetime.datetime.utcnow()
jobs.RepeatJob(
startDT=dt, # The first time to run (None if you want to start right now)
func=Callback,
args=('RepeatJob now={}, dt={}'.format(
datetime.datetime.utcnow(),
dt
),),
kwargs={'one': 'won', 'two': 'too'},
name='RepeatJob Job at {}'.format(time.asctime()),
seconds=10, # can also pass "weeks", "days", "minutes", "hours"
)
return redirect('/')
@app.route('/delete/<ID>')
def Delete(ID):
job = jobs.GetJob(int(ID))
job.Delete()
return redirect('/')
if __name__ == '__main__':
app.run(
debug=True,
threaded=True,
)
Notes
On Linux, a cron job is automatically created that runs once per minute. This could lead to your ScheduleJob() and RepeatJob() being delayed by up to 1 minute. AddJob() will always be executed ASAP.
Metadata
Release files for flask-jobs 1.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_jobs-1.0.14.tar.gz | 7.2 kB | Without provenance | Details for flask_jobs-1.0.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_jobs-1.0.14-py3-none-any.whl | Python 3 | none | any | Details for flask_jobs-1.0.14-py3-none-any.whl |
Total release size: 14.4 kB
Release files / flask_jobs-1.0.14.tar.gz
| Download URL | flask_jobs-1.0.14.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f23798dad732f1f835d72000d55a975a5dd13d229d8aff9e576be9a7ead2631
|
|
BLAKE2b-256 checksum How to use checksums |
611a14fa37caf356db393521756d33a592ac0a87f6afb34291778d385203bd7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Release files / flask_jobs-1.0.14-py3-none-any.whl
| Download URL | flask_jobs-1.0.14-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc77576e0018527248bcc4a4dac90c616bc8b9b8995840e717bb5003e4f3bcec
|
|
BLAKE2b-256 checksum How to use checksums |
c6486a6507eb9d111075464a7e54a7a6cc2f21ee523ba2245a39b3ba43e0a8fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Security for flask-jobs 1.0.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.