A Python executor for XXL-jobs
Project description
xxl-jobs 的python客户端实现
使用pyxxl可以方便的把Python写的方法注册到XXL-JOB中,使用XXL-JOB-ADMIN管理Python定时任务和周期任务
实现原理:通过XXL-JOB提供的RESTful API接口进行对接
注意!!!如果用同步的方法,极端情况下会卡住主线程。如果无法全异步编程的,谨慎使用本仓库。
已经支持的功能
- 执行器注册到job-admin
- task注册,类似于flask路由装饰器的用法
- 任务的管理(支持在界面上取消,发起等操作,任务完成后会回调admin)
- 所有阻塞策略的支持
- 异步支持(推荐)
- job-admin上查看日志
适配的XXL-JOB版本
- XXL-JOB:2.3.0
如遇到不兼容的情况请issue告诉我XXL-JOB版本我会尽量适配
如何使用
pip install pyxxl
# 如果日志需要写入redis
pip install pyxxl[redis]
# 如果需要从.env加载配置
pip install pyxxl[dotenv]
# 安装所有功能
pip install pyxxl[all]
import asyncio
from pyxxl import ExecutorConfig, PyxxlRunner
config = ExecutorConfig(
xxl_admin_baseurl="http://localhost:8080/xxl-job-admin/api/",
executor_app_name="xxl-job-executor-sample",
executor_host="172.17.0.1",
)
app = PyxxlRunner(config)
@app.handler.register(name="demoJobHandler")
async def test_task():
await asyncio.sleep(5)
return "成功..."
# 如果你代码里面没有实现全异步,请使用同步函数,不然会阻塞其他任务
@app.handler.register(name="xxxxx")
def test_task3():
return "成功3"
app.run_executor()
更多示例和接口文档请参考 PYXXL文档 ,具体代码在example文件夹下面
开发人员
下面是开发人员如何快捷的搭建开发调试环境
启动xxl的调度中心
./init_dev_env.sh
启动执行器
# if you need. set venv in project.
# poetry config virtualenvs.in-project true
poetry install --all-extras
# 修改app.py中相关的配置信息,然后启动
poetry run python example/app.py
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
pyxxl-0.3.0a3.tar.gz
(34.3 kB
view details)
Built Distribution
pyxxl-0.3.0a3-py3-none-any.whl
(41.1 kB
view details)
File details
Details for the file pyxxl-0.3.0a3.tar.gz
.
File metadata
- Download URL: pyxxl-0.3.0a3.tar.gz
- Upload date:
- Size: 34.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bf16b90d4988d657239d8d53d4527d425b7f39605c622aab3ccb09790256231 |
|
MD5 | c9502cd3b7c4e48b6a93317680ac81b2 |
|
BLAKE2b-256 | b0755aab81ffe72a8b5af48c31ddc3135691c4e7884fa5cb99387dafca2a0f19 |
Provenance
File details
Details for the file pyxxl-0.3.0a3-py3-none-any.whl
.
File metadata
- Download URL: pyxxl-0.3.0a3-py3-none-any.whl
- Upload date:
- Size: 41.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2a53b6a08a0f0cba2c9f6053da1dba9dfc5484e777774942701711424a82b5a |
|
MD5 | baa4562b4a99616f1ba70e287e200174 |
|
BLAKE2b-256 | 2f0e87a32e01351f8fd1b33b794f4b9a78156de43304fc39b9ec6c594fd1cc0c |