Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
使用pyxxl可以方便的把Python写的方法注册到XXL-JOB中,使用XXL-JOB-ADMIN管理Python定时任务和周期任务
实现原理:通过XXL-JOB提供的RESTful API接口进行对接
注意!!!如果用同步的方法,请查看下面同步任务注意事项。
2.4.0,2.3.0,2.2.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.register(name="demoJobHandler")
async def test_task():
await asyncio.sleep(5)
return "成功..."
# 如果你代码里面没有实现全异步,请使用同步函数,不然会阻塞其他任务
@app.register(name="xxxxx")
def test_task3():
return "成功3"
app.run_executor()
更多示例和接口文档请参考 PYXXL文档 ,具体代码在example文件夹下面
如果executor服务无法直连xxl-admin,请参考PYXXL配置修改executor_listen_host
pip install "pyxxl[metrics]"
安装metrics扩展后,执行器会自动加载prometheus的指标监控功能
访问地址为: http://executor_listen_host:executor_listen_port/metrics
同步任务会放到线程池中运行,无法正确接受cancel信号和timeout配置
如果需要使用同步任务并且无法控制(预料)里面执行时间,又需要进行超时和cancel功能的,需要接受pyxxl发出的cancel_event,当该cancel_event被设置时需要中断任务,下面是一个案例:
...
@app.register(name="sync_func")
def sync_loop_demo():
# 如果同步任务里面有循环,为了支持cancel操作,必须每次都判断g.cancel_event.
task_params_list = []
while not g.cancel_event.is_set() and task_parasm_list:
params = task_params_list.pop()
time.sleep(3)
return "ok"
# 如下代码会造成线程池里的线程被永远占用,timeout cancel全部不生效
@app.register(name="sync_func2")
def sync_loop_demo2():
while True:
time.sleep(3) # 模拟你运行的任务
return "ok"
由于种种3.9之后才加入的语法与特性,减少开发与适配成本,计划后续版本不再适配Python3.9以下版本,0.3.0最后一个支持Python3.8的版本
访问xxl-admin接口时支持从环境变量读取代理(列如HTTP_PROXY)
下面是开发人员如何快捷的搭建开发调试环境
./init_dev_env.sh
# if you need. set venv in project.
pip install -e ".[dev,all]"
# 修改app.py中相关的配置信息,然后启动
python example/executor_app.py
FAQs
A Python executor for XXL-jobs
We found that pyxxl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.