Skip to content

fix: Autofill startedAt and completedAt#284

Merged
adityachoudhari26 merged 1 commit intomainfrom
autofill-job-started-and-completed
Jan 20, 2025
Merged

fix: Autofill startedAt and completedAt#284
adityachoudhari26 merged 1 commit intomainfrom
autofill-job-started-and-completed

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Jan 20, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced job timestamp management during job updates
    • Automatically tracks job start and completion times based on status changes
    • Intelligently handles timestamp assignments when updating job records

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 20, 2025

Walkthrough

The pull request introduces enhanced timestamp management for job updates in the job dispatch system. Two new functions, getStartedAt and getCompletedAt, are added to dynamically compute job timestamps based on status transitions. These functions intelligently handle timestamp assignment by checking the previous job state, current updates, and job status changes, ensuring accurate tracking of job lifecycle events.

Changes

File Change Summary
packages/job-dispatch/src/job-update.ts - Added getStartedAt function to compute startedAt timestamp
- Added getCompletedAt function to compute completedAt timestamp
- Modified import to include exitedStatus
- Updated updateJob to use computed timestamp updates

Sequence Diagram

sequenceDiagram
    participant Job as Existing Job
    participant Update as Job Update Request
    participant Timestamp as Timestamp Computation
    participant Database as Job Database

    Job->>Update: Receive update request
    Update->>Timestamp: Compute startedAt
    Timestamp-->>Update: Determined startedAt
    Update->>Timestamp: Compute completedAt
    Timestamp-->>Update: Determined completedAt
    Update->>Database: Save updated job with timestamps
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

🐰 Timestamps dance, a rabbit's delight,
Job status shifts from pending to bright,
Tracking moments with algorithmic grace,
Each transition finds its rightful place,
Code hops forward, timestamps take flight! 🕒

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/job-dispatch/src/job-update.ts (2)

52-62: Add type safety for status comparisons.

While the logic is sound, consider adding type safety for the status comparisons:

-  const isPreviousStatusPending = jobBeforeUpdate.status === JobStatus.Pending;
-  const isCurrentStatusInProgress = updates.status === JobStatus.InProgress;
+  const isPreviousStatusPending = jobBeforeUpdate.status as JobStatus === JobStatus.Pending;
+  const isCurrentStatusInProgress = updates.status != null && updates.status as JobStatus === JobStatus.InProgress;

The function correctly implements a priority-based approach for determining the startedAt timestamp:

  1. Uses provided timestamp if available
  2. Preserves existing timestamp if present
  3. Sets timestamp on Pending -> InProgress transition

64-79: Strengthen null checks for status transitions.

The function implements a robust completion timestamp logic. Consider making the null check more explicit:

   const isPreviousStatusExited = exitedStatus.includes(
-    jobBeforeUpdate.status as JobStatus,
+    jobBeforeUpdate.status as JobStatus
   );
   const isCurrentStatusExited =
     updates.status != null &&
-    exitedStatus.includes(updates.status as JobStatus);
+    exitedStatus.includes(updates.status as JobStatus);

The function correctly:

  1. Prioritizes explicit timestamps
  2. Preserves existing completion time
  3. Sets timestamp on transition to exited status
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72ce04f and a501ce7.

📒 Files selected for processing (1)
  • packages/job-dispatch/src/job-update.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
packages/job-dispatch/src/job-update.ts (1)

Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
🔇 Additional comments (2)
packages/job-dispatch/src/job-update.ts (2)

5-5: LGTM!

The import statement correctly includes the exitedStatus enum which is used for job status transition checks.


93-99: Verify impact on job completion handlers.

The timestamp computation and update logic look correct. However, let's verify that the job completion handlers (onJobCompletion and onJobFailure) are compatible with the new timestamp management:

✅ Verification successful

Timestamp management is consistent across job updates

The webhook handlers and job update logic consistently manage timestamps, with proper computation of completedAt based on job completion status and correct propagation through the update interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for timestamp usage in completion handlers
echo "Checking onJobCompletion usage of timestamps:"
rg -A 5 "onJobCompletion.*startedAt|completedAt" --type ts

echo "Checking onJobFailure usage of timestamps:"
rg -A 5 "onJobFailure.*startedAt|completedAt" --type ts

Length of output: 7088

@adityachoudhari26 adityachoudhari26 merged commit 62baee9 into main Jan 20, 2025
@adityachoudhari26 adityachoudhari26 deleted the autofill-job-started-and-completed branch January 20, 2025 04:19
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