Add task timeout option to prevent long-running tasks
This PR implements a task timeout feature that allows users to specify a maximum execution time for tasks. If a task runs longer than the specified timeout, it will be automatically terminated with a clear error message.
Changes Made
Schema Updates:
- Added optional
timeoutproperty to all task schemas (run.yml,exec.yml,signal.yml) - Timeout value must be a positive integer representing seconds
- Property is optional to maintain backward compatibility
Implementation:
-
RunTask: Uses
Promise.race()to compete docker run execution against timeout, with container cleanup on timeout - ExecTask: Implements timeout for docker exec operations with proper stream handling
- SignalTask: Adds timeout support for signal sending operations
- All task types properly clean up timeout handlers to prevent memory leaks
Documentation:
- Updated
docs/tasks.mdwith timeout parameter description and examples - Added usage examples showing
timeout: 30syntax
Testing:
- Added comprehensive tests for all three task types covering both success and timeout scenarios
- Tests verify proper error messages and cleanup behavior
- All existing tests continue to pass (35/35)
Usage Example
tasks:
backup-data:
type: run
image: busybox
command: ./backup-script.sh
timeout: 300 # 5 minute timeout
health-check:
type: exec
container: web-server
command: curl -f http://localhost/health
timeout: 10 # 10 second timeout
Tasks that exceed their timeout will fail with a clear error message: Task timed out after X seconds
This feature helps prevent jobs from hanging indefinitely due to stuck containers or long-running operations, improving the reliability and predictability of scheduled tasks.
Fixes #12.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
@nicomt 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.
I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.