a distributed scheduled task scheduling component written for fast-api
Project description
fast_job
- name = "fast_job"
- description = "Provides scheduling apis and scheduling and task-related services"
- authors = ["Euraxluo euraxluo@qq.com"]
- license = "The MIT LICENSE"
- repository = "https://github.com/Euraxluo/fast_job"
- coverage : 74%
- version : 0.1.*
install
pip install fast-job
UseAge
1.wrapper function to build task
from fast_job import *
@schedule.task('task1', summer="test_task_1", tag='test', description="test_task_1")
def test(tag: int):
print({"msg": "test_task_1", "tag": tag})
return {"msg": "test_task_1", "tag": tag}
@schedule.task('task2', summer="test_task_2", tag='test', description="test_task_2")
def test2(tag: int):
print({"msg": "test_task_2", "tag": tag})
return {"msg": "test_task_2", "tag": tag}
@schedule.task('task3', summer="test_task_3", tag='test', description="test_task_3")
def task3(tag: int):
raise Exception(str({"msg": "test_task_2", "tag": tag}))
2.include in your fastApi
from loguru import logger
from fastapi import FastAPI
from example.jobs import schedule, fast_job_api_router
from example.conftest import rdb as redis
app = FastAPI()
@app.on_event("startup")
async def registry_schedule():
schedule.setup(prefix='test:', logger=logger, redis=redis, distributed=True)
@app.on_event("shutdown") # 关闭调度器
async def shutdown_connect():
schedule.shutdown()
prefix = "/test"
app.include_router(fast_job_api_router, prefix=prefix, tags=["jobs"]) # include router
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fast_job-0.1.17.tar.gz
(15.1 kB
view hashes)
Built Distribution
fast_job-0.1.17-py3-none-any.whl
(18.1 kB
view hashes)
Close
Hashes for fast_job-0.1.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b54baff224175f69e487e83c9c17c113673ba79fcd11febe068f1558448e14a |
|
MD5 | 19f16316f03169b1aa6a69d50ff12ef3 |
|
BLAKE2b-256 | d1a54c245de0d3db63cd76156cbc25f1e2ad41d32a24474553b7a2316ba1cb19 |