Skip to main content

An easy job scheduling interface for flask projects.

Project description

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)


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,
    )

Project details


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.34.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

flask_jobs-0.0.34-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file flask_jobs-0.0.34.tar.gz.

File metadata

  • Download URL: flask_jobs-0.0.34.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using 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.48.2 CPython/3.8.2

File hashes

Hashes for flask_jobs-0.0.34.tar.gz
Algorithm Hash digest
SHA256 9bf94b6d5eaca4a90448055c756967eb1f7386734b19ba8c79e6fdffdd3ed1e7
MD5 b71e676c12136a729bf1c6e33ac394ee
BLAKE2b-256 4c993faeae4dc6b36bcd9a330e2403bd7ff2d82dbb751c1d0d44d31cdeac691a

See more details on using hashes here.

File details

Details for the file flask_jobs-0.0.34-py3-none-any.whl.

File metadata

  • Download URL: flask_jobs-0.0.34-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using 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.48.2 CPython/3.8.2

File hashes

Hashes for flask_jobs-0.0.34-py3-none-any.whl
Algorithm Hash digest
SHA256 97a92506e81d014e94bb58b637ee39669549168e8778e49c70a78f6d83b4475a
MD5 b29950952bdc140458dba14aa1ffd0ef
BLAKE2b-256 88d5cf6295bcec108a81863b066f123c6ba93d642ba0f8f675ca8e5168b1d035

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page