Skip to content

Conversation

@vkarpov15
Copy link
Member

No description provided.

…g tasks that were scheduled for a long time ago
@vkarpov15 vkarpov15 requested a review from Copilot October 3, 2025 13:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves task handling by implementing better timeout mechanisms to prevent stuck tasks. It introduces two new timeout features: scheduling timeouts for tasks that wait too long to start, and execution timeouts for tasks that run too long.

  • Adds schedulingTimeoutAt and timeoutAt fields to handle different types of task timeouts
  • Implements automatic expiration of timed-out tasks with new status types (timed_out, scheduling_timed_out)
  • Refactors repeating task logic into a shared helper function

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

File Description
src/taskSchema.js Core implementation of timeout handling, new schema fields, and refactored task execution logic
test/task.test.js Comprehensive test coverage for timeout scenarios and repeating task behavior
package.json Added ESLint dependencies for code quality
eslint.config.js ESLint configuration for the project

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

previousTaskId: task._id,
originalTaskId: task.originalTaskId || task._id,
timeoutMS: task.timeoutMS,
schedulingTimeoutAt: scheduledAt.valueOf() + 10 * 60 * 1000
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 10 * 60 * 1000 (10 minutes) is repeated multiple times. Consider extracting this into a named constant like DEFAULT_SCHEDULING_TIMEOUT_MS to improve maintainability.

Copilot uses AI. Check for mistakes.
{ status: 'in_progress', startedRunningAt: now, ...additionalParams },
{
status: 'in_progress',
timeoutAt: new Date(now.valueOf() + 10 * 60 * 1000), // 10 minutes from startedRunningAt
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same magic number 10 * 60 * 1000 (10 minutes) should be extracted into a constant. Consider creating DEFAULT_EXECUTION_TIMEOUT_MS for consistency.

Copilot uses AI. Check for mistakes.
scheduledAt,
params,
repeatAfterMS,
schedulingTimeoutAt: scheduledAt.valueOf() + 10 * 60 * 1000,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of the magic number 10 * 60 * 1000. This should use the same constant as the other timeout values.

Suggested change
schedulingTimeoutAt: scheduledAt.valueOf() + 10 * 60 * 1000,
schedulingTimeoutAt: scheduledAt.valueOf() + time.TEN_MINUTES_MS,

Copilot uses AI. Check for mistakes.
previousTaskId: task._id,
originalTaskId: task.originalTaskId || task._id,
timeoutMS: task.timeoutMS,
schedulingTimeoutAt: scheduledAt.valueOf() + 10 * 60 * 1000
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fourth occurrence of the magic number. All instances of 10 * 60 * 1000 should reference the same constant.

Copilot uses AI. Check for mistakes.
vkarpov15 and others added 5 commits October 3, 2025 10:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vkarpov15 vkarpov15 merged commit 779af70 into main Oct 3, 2025
4 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/scheduling-timeouts branch October 3, 2025 14: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.

2 participants