Skip to content

fix: Add started_at and completed_at on jobs#283

Merged
jsbroks merged 3 commits intomainfrom
job-duration
Jan 20, 2025
Merged

fix: Add started_at and completed_at on jobs#283
jsbroks merged 3 commits intomainfrom
job-duration

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Jan 19, 2025

Summary by CodeRabbit

  • New Features

    • Added start and completion timestamps for job tracking.
    • Enhanced workflow webhook event handling with more detailed job status information.
  • Database Changes

    • Updated job table schema to include started_at and completed_at columns.
    • Added new database migration to support job lifecycle tracking.
  • API Updates

    • Enhanced Job schema to include startedAt and completedAt properties for better job lifecycle tracking.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 19, 2025

Warning

Rate limit exceeded

@adityachoudhari26 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b485d3d and af094cc.

📒 Files selected for processing (1)
  • packages/job-dispatch/src/__test__/job-variables-deployment.test.ts (1 hunks)

Walkthrough

This pull request introduces enhancements to job tracking and workflow webhook event handling. The changes add two new timestamp columns (started_at and completed_at) to the job database schema, enabling more precise tracking of job lifecycle events. The webhook handler for GitHub workflow events has been updated to capture and store additional timing information, specifically the start and completion times of jobs. These modifications provide more granular insights into job execution by recording when jobs begin and end.

Changes

File Change Summary
apps/webservice/src/app/api/github/webhook/workflow/handler.ts Updated workflow webhook event handling to include startedAt and completedAt variables, modified updateJob function call with new timing parameters.
packages/db/drizzle/0057_keen_trish_tilby.sql Added started_at and completed_at timestamp columns to the job table.
packages/db/drizzle/meta/_journal.json Added new migration entry for version 7.
packages/db/src/schema/job.ts Added startedAt and completedAt timestamp fields to job table schema.
openapi.v1.json Added startedAt and completedAt properties to Job schema in OpenAPI specification.

Sequence Diagram

sequenceDiagram
    participant GitHub as GitHub Webhook
    participant Handler as Workflow Webhook Handler
    participant Database as Job Database

    GitHub->>Handler: Send Workflow Run Event
    Handler->>Handler: Extract Job Timing Information
    Handler->>Database: Update Job with Start/Completion Times
    Database-->>Handler: Confirmation
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

🐰 Hop, hop, through the code we go,
Tracking jobs with timestamps in tow,
Started and finished, now crystal clear,
Workflow magic brings data so dear!
Rabbit's wisdom in every line, 🕒
Making tracking simply divine! 🚀


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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f799762 and 490a557.

📒 Files selected for processing (4)
  • apps/webservice/src/app/api/github/webhook/workflow/handler.ts (3 hunks)
  • packages/db/drizzle/0057_keen_trish_tilby.sql (1 hunks)
  • packages/db/drizzle/meta/_journal.json (1 hunks)
  • packages/db/src/schema/job.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
packages/db/src/schema/job.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.

apps/webservice/src/app/api/github/webhook/workflow/handler.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: Lint
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (5)
apps/webservice/src/app/api/github/webhook/workflow/handler.ts (2)

73-76: Great documentation!

The comment explaining the use of updated_at as a proxy for completion time is very helpful for future maintenance.


82-83: LGTM! Clean metadata structure.

The simplified Links metadata structure and the inclusion of timing information in the job update look good.

packages/db/src/schema/job.ts (1)

94-95: LGTM! Well-defined schema changes.

The new timestamp fields are correctly defined with timezone support and are appropriately nullable, which is essential for tracking job lifecycle events.

packages/db/drizzle/0057_keen_trish_tilby.sql (1)

1-2: LGTM! Clean and correct migration.

The migration properly adds the new timestamp columns with timezone support, matching the schema definition.

packages/db/drizzle/meta/_journal.json (1)

404-409: LGTM! Properly formatted journal entry.

The migration journal entry is correctly structured and maintains consistency with existing entries.

? convertConclusion(conclusion)
: convertStatus(externalStatus);

const startedAt = new Date(run_started_at);
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot Jan 19, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for run_started_at.

The run_started_at field should be checked for null before creating the Date object to prevent potential runtime errors.

-const startedAt = new Date(run_started_at);
+const startedAt = run_started_at ? new Date(run_started_at) : null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const startedAt = new Date(run_started_at);
const startedAt = run_started_at ? new Date(run_started_at) : null;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

run_started_at is type string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@adityachoudhari26 I've verified the usage pattern in the codebase which confirms your statement. No further changes are needed.

🔗 Analysis chain

@adityachoudhari26 You are correct. Since run_started_at is of type string, the null check is unnecessary. The current implementation is correct. I apologize for the confusion in my previous review comment.



🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for WorkflowRunEvent type definition or usage
ast-grep --pattern 'type WorkflowRunEvent = {
  $$$
  run_started_at: $_
  $$$
}'

Length of output: 83


Script:

#!/bin/bash
# Search for WorkflowRunEvent usage and type information
rg -A 5 "WorkflowRunEvent" --type ts

Length of output: 3654


Script:

#!/bin/bash
# Search for run_started_at usage
rg "run_started_at" --type ts -C 3

Length of output: 1290


✏️ Learnings added
Learnt from: adityachoudhari26
PR: ctrlplanedev/ctrlplane#283
File: apps/webservice/src/app/api/github/webhook/workflow/handler.ts:70-70
Timestamp: 2025-01-19T19:16:45.094Z
Learning: In the GitHub webhook workflow handler, the `run_started_at` field from WorkflowRunEvent is of type string and does not require a null check before creating a Date object.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

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 (1)
openapi.v1.json (1)

2658-2667: Add descriptions to the new timestamp properties.

The implementation of startedAt and completedAt properties is correct, using appropriate types and nullability. Consider adding descriptions to clarify their purpose:

 "startedAt": {
   "type": "string",
   "format": "date-time",
-  "nullable": true
+  "nullable": true,
+  "description": "Timestamp when the job started execution"
 },
 "completedAt": {
   "type": "string",
   "format": "date-time",
-  "nullable": true
+  "nullable": true,
+  "description": "Timestamp when the job finished execution (successfully or with failure)"
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 490a557 and b485d3d.

📒 Files selected for processing (1)
  • openapi.v1.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)

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