Skip to main content

dev-task-scheduler

轻量、可靠、可观测的本地定时任务调度框架。

特性

  • 核心调度引擎:基于 APScheduler,支持 cron/interval/date 三种触发器
  • 幂等校验:防止重复执行,支持自定义键表达式
  • 重试策略:指数退避 + 抖动 + 死信队列,可扩展回调
  • 超时控制:三级超时(线程/信号/进程),智能策略选择
  • 状态持久化:SQLite 存储,崩溃自动恢复
  • 执行记录:CSV 审计日志,支持轮转和多条件查询
  • 告警通知:模板化告警 + Webhook + 系统通知
  • CLI 工具:start/status/list/run/history/stats/cleanup/recover/validate
  • 配置管理:YAML 配置 + 环境变量覆盖(30+ 变量)+ 校验
  • 跨项目复用:PROJECT_ROOT 三级优先级,多项目上下文隔离

安装

pip install dev-task-scheduler

快速开始

from scheduler import SchedulerApp
from scheduler.config import load_config

# 加载配置
config = load_config("scheduler.yaml")

# 创建调度器
app = SchedulerApp(config)

# 注册任务
@app.task(name="daily_report", trigger="cron", hour=8, minute=0)
def daily_report():
    print("生成日报")

# 启动
app.start()

配置

scheduler:
  max_concurrent: 3
  default_timeout: 300

tasks:
  - name: daily_report
    func_ref: "my_module:daily_report"
    trigger_type: cron
    trigger_args:
      hour: 8
      minute: 0

idempotency:
  enabled: true
  key_ttl: 3600

retry:
  enabled: true
  max_retries: 3
  base_delay: 1.0
  backoff_factor: 2.0

recording:
  enabled: true
  csv_path: "logs/executions.csv"

alerting:
  enabled: true
  webhook_url: "https://hooks.example.com/xxx"

环境变量

所有配置项支持 SCHEDULER_ 前缀环境变量覆盖:

export SCHEDULER_SCHEDULER__MAX_CONCURRENT=5
export SCHEDULER_IDEMPOTENCY__ENABLED=true
export SCHEDULER_RECORDING__CSV_PATH=/var/log/scheduler.csv

CLI 命令

# 启动调度器
dev-task-scheduler start

# 查看状态
dev-task-scheduler status

# 手动触发任务
dev-task-scheduler run <task_name>

# 查看历史记录
dev-task-scheduler history [--limit 20]

# 查看统计
dev-task-scheduler stats

# 清理过期数据
dev-task-scheduler cleanup

# 崩溃恢复
dev-task-scheduler recover

# 校验配置
dev-task-scheduler validate

文档

开发

# 克隆仓库
git clone https://github.com/your-org/dev-task-scheduler.git
cd dev-task-scheduler

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest --cov=scheduler --cov-fail-under=80

# 代码检查
ruff check .
ruff format --check .

许可证

MIT License

Metadata

Release files for dev-task-scheduler 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dev-task-scheduler 1.0.0
File Size Uploaded Provenance
dev_task_scheduler-1.0.0.tar.gz 188.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dev-task-scheduler 1.0.0
File Interpreter ABI Platform
dev_task_scheduler-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 368.1 kB

Release files / dev_task_scheduler-1.0.0.tar.gz

Download URL dev_task_scheduler-1.0.0.tar.gz
Size 188.9 kB
Tags Source
SHA-256 checksum
How to use checksums
871b8b7622b54d94b5545b6f5157935e2cd2db09f1f1f38d0f29722e507cabee
BLAKE2b-256 checksum
How to use checksums
9be10bf853b76e1f72582f6153ab3d6b2e5df4b269148142a6d224d8802ab416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Release files / dev_task_scheduler-1.0.0-py3-none-any.whl

Download URL dev_task_scheduler-1.0.0-py3-none-any.whl
Size 179.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9b2573671d96d03562e630e4ddfc939d325bdac8ebb4a4b404554125674fa36
BLAKE2b-256 checksum
How to use checksums
6e9f097e66f58a6d98ffb8a82ee3fa2eb7524da0df2c172fe41910531a867d31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9

Security for dev-task-scheduler 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page