• Stars
    star
    100
  • Rank 340,703 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 5 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple Flask scheduled tasks without extra daemons

flask-crontab

Simple Flask scheduled tasks without extra daemons

PyPI PyPI - Python Version Github Action Supported Platforms

This project is strongly inspired by django-crontab, and only works on Python 3.5+. Due to the coming EOL of Python 2 on 2020/01/01, there is no plan for Python 2 support.

Quick Start

Install via pip:

$ pip install flask-crontab

Instantiate the extension in your app.py after the creation of Flask app:

from flask import Flask
from flask_crontab import Crontab

app = Flask(__name__)
crontab = Crontab(app)

If you are using App Factory pattern, you can also register the extension later:

crontab = Crontab()

def create_app():
    ...
    crontab.init_app(app)

Now create a scheduled job:

@crontab.job(minute="0", hour="6")
def my_scheduled_job():
    do_something()

An app context is automatically activated for every job run, so that you can access objects that are attached to app context. Then add the job to crontab:

$ flask crontab add

That's it! If you type in crontab -l in your shell, you can see some new lines created by flask-crontab.

Show jobs managed by current app:

$ flask crontab show

Purge all jobs managed by current app:

$ flask crontab remove

Run a specific job given by hash:

$ flask crontab run <job_hash>

See supported options via --help for every commands.

Decorator API

def job(
    minute: str = "*",
    hour: str = "*",
    day: str = "*",
    month: str = "*",
    day_of_week: str = "*",
    args: Tuple[Any, ...] = (),
    kwargs: Optional[Dict[str, Any]] = None,
) -> Callable:

The decorator accepts five arguments minute, hour, day, month, day_of_month, which are the same as crontab 5-parts time format. Any part that is not given defaults to *. Besides, job decorator accepts args and kwargs which will be passed to the decorated function as positional arguments and keywords arguments, respectively.

Configuration

Config item Description Default value
CRONTAB_EXECUTABLE The absolute path of crontab /usr/bin/crontab
CRONTAB_LOCK_JOBS Whether lock jobs when running False

License

This project is publised under MIT license.

More Repositories

1

legit

Git for Humans, Inspired by GitHub for Mac™.
Python
5,702
star
2

marko

A markdown parser with high extensibility.
Python
342
star
3

tetos

A unified interface for multiple Text-to-Speech (TTS) providers.
Python
221
star
4

python-cfonts

Sexy fonts for the console
Python
192
star
5

Flog

A Simple Blog Powered by Flask
Vue
191
star
6

unearth

A utility to fetch and download python packages
Python
139
star
7

monas

Python monorepo made easy
Python
77
star
8

wordle-tui

Play WORDLE game in your terminal.
Python
61
star
9

pipfile-requirements

A CLI tool to covert Pipfile/Pipfile.lock to requirments.txt
Python
50
star
10

flask-vue-todo

A todo app with Vue and backed by Flask
Python
48
star
11

pdm-packer

A PDM plugin that packs your packages into a zipapp
Python
46
star
12

onepm

Picks the right package manager for you
Python
44
star
13

picguessr

Python
41
star
14

findpython

A utility to find python versions on your system
Python
36
star
15

fix-future-annotations

A CLI and pre-commit hook to fix future annotations
Python
35
star
16

oven

TypeScript
27
star
17

resume

Personal resume with a handwritten SSG
Python
24
star
18

pdm-vscode

DEPRECATED: A PDM plugin that autogenerates workspace vscode settings for you
Python
23
star
19

pycomplete

A Python library to generate static completion scripts for your CLI app
Python
22
star
20

frostming

My profile, including a chess game
Python
17
star
21

enum-adt

Python
13
star
22

renren-dumps

人人网数据备份器
Python
12
star
23

atoml

Yet another style-preserving TOML library for Python
Python
12
star
24

modul

Python modules with public exports
Python
12
star
25

lektor-tailwind

A Lektor plugin that adds Tailwind CSS to your project seamlessly
Python
11
star
26

flask-webconsole-example

A simple example of web console
HTML
10
star
27

rediswrapper

Pythonic wrapper for Redis Client.
Python
10
star
28

pbs-installer

Python
9
star
29

tokei-pie-cooker

Visualize your code statistics with Pie Chart
Python
8
star
30

scoop-frostming

My personal scoop bucket
PowerShell
7
star
31

pofmt

Your missing PO formatter and linter
Python
7
star
32

myrc

My personal profiles for Win and Mac
Shell
5
star
33

monas-example-repo

Serve as an example of how Monas manage a monorepo
Python
4
star
34

pep665_poc

A POC implementation of PEP 665
Python
4
star
35

pdm-mypyc

A build hook to compile source files with mypyc
Python
4
star
36

hexo-theme-landing-page

Hexo ported theme of Landing Page
CSS
3
star
37

package-manager-demo

Write a package manage from scratch demo repo
Python
3
star
38

transpyler-gpt

A GPT-powered Python transpiler that makes your Python code run on older versions
Python
3
star
39

flask-remote-file

Flask extension to serve remote files via sftp
Python
2
star
40

frostming.github.io

My personal wiki site
Vue
2
star
41

sodoku-solver

Python
2
star
42

wordle-tg

A Telegram Bot that lets you play wordle with other people
Python
2
star
43

daily-trending

Daily trending digest based on people you follow
Python
2
star
44

gorella

Monkey patch regular expression methods to built-in string types
Python
1
star
45

RimeConfig

My Rime Configuration
1
star
46

highlight-lexer-comparison

Lexer comparison of code highlighters
HTML
1
star
47

vscode-mingshe

VSCode language support for MingShe
1
star
48

Codingame

My solutions of https://www.codingame.com
Python
1
star
49

scoop-action

GitHub Action for Scoop buckets
JavaScript
1
star
50

tokei

PyPI package for https://github.com/XAMPPRocky/tokei
Python
1
star
51

pdm-lock-build-deps

Python
1
star
52

pycon-python-pm

PyCon 2019深圳站演讲Slide: Python包管理及Pipenv
CSS
1
star
53

backports.html

Backport of Python 3.4+'s html module
Python
1
star
54

blog_backup

个人博客MD备份
Shell
1
star