from flask import Flask
from sche import sche, api
app = Flask(__name__)
app.config.from_object("config")
sche.init_app(app, start=True)
api.init_app(app)
if __name__ == '__main__':
app.run()
example:
from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from pytz import timezone
APSCHEDULER = {
'jobstores': {
'default': SQLAlchemyJobStore(url='sqlite:///test_scheduler.db')
},
'executors': {
'default': {
'type': 'threadpool',
'max_workers': 20
}
},
'job_defaults': {
'coalesce': False,
'max_instances': 3
},
'timezone': timezone('Asia/Shanghai'),
'funcs': "jobs"
}
jobstores | apscheduler jobstores,default None |
executors | apscheduler executors,default None |
job_defaults | apscheduler job_defaults,default None |
timezone | apscheduler timezone,default UTC |
funcs | str or list, tasks where find,default [] |
---|
- /scheduler
- GET: get all jobs
- POST: add a new job,the func is same as ‘jobs:vvv’
- /scheduler/status
- GET: get scheduler status,include running,executors,job_defaults
- POST:
start scheduler.You can pass parameter pause (default: False)
# when pause in ['1',1,'true','True'] pause = True
- DELETE:
shutdown scheduler.You can pass parameter wait (default: True)
# when wait in ['0',0,'False','false'] wait = False
- /scheduler/<pk>
- GET: get a job with id.
- PUT: modify a job with id.
- DELETE: delete a job with id.
- /scheduler/<pk>/pause
- POST: pause a job with id.
- /scheduler/<pk>/resume
- POST: resume a job with id.
- /scheduler/<pk>/execute
- POST: Executes a job with id right now.
python runserver