FastAPI-Scheduler
## Project IntroductionFastAPI-Scheduler is a simple scheduled task management FastAPI extension library based on APScheduler.
Install
pip install fastapi-scheduler
Simple example
main.py:
from fastapi import FastAPI
from fastapi_amis_admin.admin.settings import Settings
from fastapi_amis_admin.admin.site import AdminSite
from datetime import date
from fastapi_scheduler import SchedulerAdmin
# Create `FastAPI` application
app = FastAPI()
# Create `AdminSite` instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db'))
# # Custom timed task scheduler
# from apscheduler.schedulers.asyncio import AsyncIOScheduler
# from apscheduler.jobstores.redis import RedisJobStore
# # Use `RedisJobStore` to create a job store
# scheduler = AsyncIOScheduler(jobstores={'default':RedisJobStore(db=2,host="127.0.0.1",port=6379,password="test")})
# scheduler = SchedulerAdmin.bind(site,scheduler=scheduler)
# Create an instance of the scheduled task scheduler `SchedulerAdmin`
scheduler = SchedulerAdmin.bind(site)
# Add scheduled tasks, refer to the official documentation: https://apscheduler.readthedocs.io/en/master/
# use when you want to run the job at fixed intervals of time
@scheduler.scheduled_job('interval', seconds=60)
def interval_task_test():
print('interval task is run...')
# use when you want to run the job periodically at certain time(s) of day
@scheduler.scheduled_job('cron', hour=3, minute=30)
def cron_task_test():
print('cron task is run...')
# use when you want to run the job just once at a certain point of time
@scheduler.scheduled_job('date', run_date=date(2022, 11, 11))
def date_task_test():
print('date task is run...')
@app.on_event("startup")
async def startup():
# Mount the background management system
site.mount_app(app)
# Start the scheduled task scheduler
scheduler.start()
if __name__ == '__main__':
import uvicorn
uvicorn.run(app, debug=True)
Interface/UI preview
- Open
http://127.0.0.1:8000/admin/in your browser:
Dependent projects
agreement
The project follows the Apache2.0 license agreement.
Metadata
Release files for fastapi_scheduler 0.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 | |
|---|---|---|---|
| fastapi_scheduler-0.0.14.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_scheduler-0.0.14-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.6 kB
Release files / fastapi_scheduler-0.0.14.tar.gz
| Download URL | fastapi_scheduler-0.0.14.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbd48a3507d8fe1bc6a43e7811f88be7e3fa04720aa011c93e9b04d6e757224f
|
|
BLAKE2b-256 checksum How to use checksums |
caa9f72e400d42e88e3ec8cf55c7b62f554d8a6e5890ac7ebd309814b26d4737
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.10.1 CPython/3.11.0
|
Release files / fastapi_scheduler-0.0.14-py3-none-any.whl
| Download URL | fastapi_scheduler-0.0.14-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0882cc1b742caa1fdcae4578d1d858f38ac45da19689878e01274531fd2aab5c
|
|
BLAKE2b-256 checksum How to use checksums |
c6579d9a28d8381f4e2c3eff6fca60c6eab4ee2a893e6e5d8c797db667954bbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.10.1 CPython/3.11.0
|