Skip to content

Add task timeout option to prevent long-running tasks#101

Draft
nicomt with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-12
Draft

Add task timeout option to prevent long-running tasks#101
nicomt with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-12

Conversation

Copilot AI commented Sep 7, 2025

Copy link
Copy Markdown

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 timeout property 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.md with timeout parameter description and examples
  • Added usage examples showing timeout: 30 syntax

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.

Copilot AI commented Sep 7, 2025

Copy link
Copy Markdown
Author

@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.

Co-authored-by: nicomt <17040442+nicomt@users.noreply.github.com>
Copilot AI changed the title [WIP] Task Timeout Add task timeout option to prevent long-running tasks Sep 7, 2025
Copilot AI requested a review from nicomt September 7, 2025 17:40
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.

Task Timeout

2 participants