-
Notifications
You must be signed in to change notification settings - Fork 184
/
decorated.py
45 lines (29 loc) · 895 Bytes
/
decorated.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Example of decorators."""
from flask import Flask
from flask_apscheduler import APScheduler
class Config:
"""App configuration."""
SCHEDULER_API_ENABLED = True
scheduler = APScheduler()
# interval examples
@scheduler.task("interval", id="do_job_1", seconds=30, misfire_grace_time=900)
def job1():
"""Sample job 1."""
print("Job 1 executed")
# cron examples
@scheduler.task("cron", id="do_job_2", minute="*")
def job2():
"""Sample job 2."""
print("Job 2 executed")
@scheduler.task("cron", id="do_job_3", week="*", day_of_week="sun")
def job3():
"""Sample job 3."""
print("Job 3 executed")
if __name__ == "__main__":
app = Flask(__name__)
app.config.from_object(Config())
# it is also possible to enable the API directly
# scheduler.api_enabled = True # noqa: E800
scheduler.init_app(app)
scheduler.start()
app.run()