Skip to content

Dev#1

Merged
vincent067 merged 7 commits intomainfrom
dev
Feb 28, 2026
Merged

Dev#1
vincent067 merged 7 commits intomainfrom
dev

Conversation

@vincent067
Copy link
Copy Markdown
Collaborator

This pull request introduces a per-task execution timeout and adds support for flexible webhook notification controls to the task runner. The timeout ensures that tasks exceeding a specified duration are automatically killed and marked as failed, while the notification enhancements allow users to enable, disable, or customize webhook notifications via CLI flags or configuration. Several internal improvements and refactorings are also included to support these features.

Execution Timeout Feature:

  • Added a --timeout CLI flag and corresponding logic to set a maximum execution time per task (default: 2400 seconds/40 minutes). Tasks exceeding this limit are forcefully terminated and marked as failed, with graceful escalation from SIGTERM to SIGKILL. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Notification System Enhancements:

  • Added CLI flags --notify, --no-notify, --notify-each, and --wecom-webhook to control webhook notification behavior, including per-task notifications and webhook URL overrides. Notification settings are now resolved and passed to the executor. [1] [2] [3] [4] [5]

Internal Refactoring and Safety Improvements:

  • Refactored imports and initialization logic in executor.py for clarity and maintainability. Improved process cleanup to ensure no zombie processes remain, especially after timeouts or exceptions. [1] [2] [3] [4]
  • Improved signal handling and added documentation to ensure signal safety and correctness during task interruption and timeout. [1] [2]

Minor Fixes and Cleanups:

  • Improved error messages and exception chaining in delay range parsing. Cleaned up code style and minor logic in delay handling and output tail extraction. [1] [2] [3] [4] [5]
  • Added certifi to development requirements for improved SSL handling.

Issue #4 — Single-task timeout (40min default):
- Add MAX_EXECUTION_SECONDS (2400s) constant in config.py
- Add timeout check in PTY select loop and PIPE readline loop
- On timeout: SIGTERM → 5s wait → SIGKILL → mark failed (reason: timeout)
- Task execution continues to the next task after timeout
- Add --timeout CLI flag to override default per-run
- Pass timeout through run_cmd.py → executor

Issue #5a — argparse import fix:
- Add 'import argparse' at top of executor.py

Issue #5b — Subprocess cleanup enhancement:
- Add _ensure_child_cleaned_up() finally-block safety net in execute_task()

Issue #5c — Atomic write audit:
- Convert save_run_metadata() and save_run_summary() in runtime.py
  to use tmp+rename pattern

Issue #5d — Signal handler documentation:
- Document GIL atomicity guarantee for _ctrl_c_count

Issue #5e — PTY/PIPE fallback logging:
- Improved warning with exception type and colour-loss note
- 新增 task_runner/notify.py:抽象 Notifier 基类 + WeComNotifier 实现
  - 使用 urllib.request 零外部依赖
  - markdown_v2 消息格式,4096 字节 UTF-8 自动截断
  - 环境变量 TASK_RUNNER_WECOM_WEBHOOK / TASK_RUNNER_NOTIFY_ENABLED 配置
  - 预留 ABC 接口支持未来扩展钉钉/飞书
- executor.py 集成通知触发点:
  - 批次完成时发送汇总统计
  - 任务失败时发送失败详情(超时/exit code/执行过快)
  - Ctrl+C 中断时发送中断进度
  - --notify-each 可选每个任务成功也通知
- cli.py 新增 CLI 参数:
  - --notify / --no-notify 开关
  - --notify-each 每任务通知
  - --wecom-webhook URL 覆盖环境变量
- 新增 tests/test_notify.py:38 个测试用例含真实 webhook 集成测试
- 顺带修复 executor.py 已有 lint 问题 (B904/E741/E402)

Made-with: Cursor
@vincent067 vincent067 merged commit 599f617 into main Feb 28, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants