单任务受控执行(15 态状态机 + 审计轨迹)、DAG 管道、Controller 门面。
执行器三个:线程(默认,含 async def 任务)、内联(同步 / 测试)、进程
(spawn 子进程:硬性停止、绕开 GIL、崩溃隔离)。
调度:并发额度 + 每桶限流 + 具名资源信号量(按标签)+ 优先级排队。
持久层:TaskStore 契约 + 内存 / SQLite / Postgres 实现,契约测试随包发布。
跨进程与多节点:写穿 / 读穿、指令通道与租约、owned_buckets 划界、reconcile。
CLI、12 个可直接运行的示例、docs/ 下 5 份文档。
门禁:ruff / ruff format / mypy(strict) 干净;
pytest 563 passed(44 skipped 是需要真实 Postgres 的那批);
带一台可连的 Postgres 时 607 passed。
18 lines
517 B
Python
18 lines
517 B
Python
# myapp/tasks.py
|
|
from chongming_task import task
|
|
|
|
|
|
@task(tags={"io"})
|
|
def worker(ctx, source: str) -> int:
|
|
"""常驻消费。"""
|
|
processed = 0
|
|
while not ctx.is_stop_requested: # ← 优雅收尾(终态 succeeded,返回值保留)
|
|
ctx.checkpoint() # ← 不调用它 = 停不掉
|
|
processed += 1
|
|
ctx.progress(processed, unit="batch")
|
|
return processed
|
|
|
|
|
|
def register(controller): # 或者不写它,只靠 @task 也行
|
|
controller.register_module(__import__(__name__))
|