Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move variable resolution to job dispatch time #167

Merged
merged 5 commits into from
Oct 26, 2024
Merged

Conversation

zacharyblasczyk
Copy link
Member

@zacharyblasczyk zacharyblasczyk commented Oct 24, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced job dispatching by integrating the creation of release variables for dispatched jobs and triggered runbook jobs.
  • Bug Fixes

    • Simplified control flow in the ReleaseJobTriggerBuilder by removing unused functionality related to release variable creation, ensuring smoother job insertion processes.

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Warning

Rate limit exceeded

@zacharyblasczyk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 9 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

Files that changed from the base of the PR and between 32cf9aa and bbebcf6.

Walkthrough

The changes in this pull request introduce the createReleaseVariables function from the job-variables-deployment module into the DispatchBuilder class and the dispatchRunbook function within the job-dispatch.ts file. This function is invoked to create release variables for jobs being dispatched and for triggered runbook jobs, utilizing Promise.allSettled for concurrent execution and enhanced error handling. Additionally, the release-job-trigger.ts file has been updated to remove the unused createReleaseVariables import, streamlining its logic while preserving the existing functionality of the ReleaseJobTriggerBuilder class.

Changes

File Path Change Summary
packages/job-dispatch/src/job-dispatch.ts Integrated createReleaseVariables into DispatchBuilder and dispatchRunbook, using Promise.allSettled for error handling.
packages/job-dispatch/src/release-job-trigger.ts Removed unused createReleaseVariables import; simplified control flow in ReleaseJobTriggerBuilder's insert method.

Possibly related PRs

  • fix: Show job external url #154: The changes in this PR involve the removal of the createReleaseVariables import, which is directly related to the main PR's introduction of the createReleaseVariables function into the DispatchBuilder class and its usage in job dispatching.
  • fix: External url button #158: This PR discusses modifications to the dispatchGithubJob function, including the handling of the externalUrl variable, which is relevant to the main PR's focus on job-related data processing and error handling in job dispatching.

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

@zacharyblasczyk zacharyblasczyk changed the title Move variable resolution to job creation time Move variable resolution to job dispatch time Oct 24, 2024
Copy link
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: 2

🧹 Outside diff range and nitpick comments (1)
packages/job-dispatch/src/job-dispatch.ts (1)

Line range hint 71-116: Review transaction management across async operations

The code performs multiple async operations (variable creation, queue updates, status updates) using a passed-in transaction. There's a risk of partial completion if the transaction isn't properly managed at the caller level.

Consider:

  1. Documenting the transaction requirements for callers
  2. Ensuring the passed transaction is committed atomically with queue operations
  3. Adding integration tests to verify atomicity of these operations

Would you like me to help create a test suite that verifies the transaction boundaries?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2899756 and 24325f7.

📒 Files selected for processing (2)
  • packages/job-dispatch/src/job-dispatch.ts (3 hunks)
  • packages/job-dispatch/src/release-job-trigger.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/job-dispatch/src/release-job-trigger.ts
🔇 Additional comments (1)
packages/job-dispatch/src/job-dispatch.ts (1)

9-9: LGTM: Clean import addition

The import is appropriately placed and follows the existing import organization pattern.

packages/job-dispatch/src/job-dispatch.ts Outdated Show resolved Hide resolved
packages/job-dispatch/src/job-dispatch.ts Outdated Show resolved Hide resolved
Copy link
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: 2

🧹 Outside diff range and nitpick comments (1)
packages/job-dispatch/src/job-dispatch.ts (1)

Based on the results, I can now provide the final response:

Error handling improvements needed for dispatch() and dispatchRunbook() callers

The verification reveals that most callers don't properly handle potential errors from the variable resolution process. Specific issues:

  • None of the dispatch() callers wrap the call in try-catch blocks:

    • packages/api/src/router/job.ts
    • packages/api/src/router/release.ts (multiple locations)
    • packages/api/src/router/environment.ts
    • apps/webservice/src/app/api/v1/releases/route.ts
    • apps/webservice/src/app/api/v1/config/route.ts
    • apps/jobs/src/policy-checker/index.ts
  • The dispatchRunbook caller in packages/api/src/router/runbook.ts doesn't handle potential errors either.

Since these functions can now fail during variable resolution, errors should be caught and handled appropriately to prevent unhandled promise rejections and provide proper error feedback to users.

🔗 Analysis chain

Line range hint 1-142: Verify error handling in callers

Since both dispatch() and dispatchRunbook() functions can now throw errors during variable resolution, we should verify that all callers handle these errors appropriately.

Let's check the usage:


Let me generate additional scripts to verify the error handling in the callers we found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all callers of dispatch() and dispatchRunbook()
echo "Searching for dispatch() callers:"
rg -A 3 "dispatch\(\)" --type ts

echo -e "\nSearching for dispatchRunbook callers:"
rg -A 3 "dispatchRunbook\(" --type ts

# Verify the removal of createReleaseVariables from release-job-trigger
echo -e "\nVerifying removal from release-job-trigger:"
rg "createReleaseVariables" "release-job-trigger.ts"

Length of output: 2871


Script:

#!/bin/bash
# Check error handling in dispatch() callers
echo "Checking error handling in dispatch() callers:"

echo -e "\nChecking packages/job-creation.ts:"
rg -B 5 -A 5 "dispatch\(\)" packages/job-creation.ts

echo -e "\nChecking packages/api/src/router/job.ts:"
rg -B 5 -A 5 "dispatch\(\)" packages/api/src/router/job.ts

echo -e "\nChecking packages/api/src/router/release.ts:"
rg -B 5 -A 5 "dispatch\(\)" packages/api/src/router/release.ts

echo -e "\nChecking packages/api/src/router/environment.ts:"
rg -B 5 -A 5 "dispatch\(\)" packages/api/src/router/environment.ts

echo -e "\nChecking apps/webservice/src/app/api/v1/releases/route.ts:"
rg -B 5 -A 5 "dispatch\(\)" apps/webservice/src/app/api/v1/releases/route.ts

echo -e "\nChecking apps/webservice/src/app/api/v1/config/route.ts:"
rg -B 5 -A 5 "dispatch\(\)" apps/webservice/src/app/api/v1/config/route.ts

echo -e "\nChecking apps/jobs/src/policy-checker/index.ts:"
rg -B 5 -A 5 "dispatch\(\)" apps/jobs/src/policy-checker/index.ts

echo -e "\nChecking dispatchRunbook error handling:"
rg -B 5 -A 5 "dispatchRunbook\(" packages/api/src/router/runbook.ts

Length of output: 4266

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 24325f7 and 7ed5fa2.

📒 Files selected for processing (1)
  • packages/job-dispatch/src/job-dispatch.ts (3 hunks)
🔇 Additional comments (1)
packages/job-dispatch/src/job-dispatch.ts (1)

9-9: LGTM: Import statement is correctly placed

The import of createReleaseVariables is properly organized with related imports.

packages/job-dispatch/src/job-dispatch.ts Outdated Show resolved Hide resolved
packages/job-dispatch/src/job-dispatch.ts Outdated Show resolved Hide resolved
Copy link
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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7ed5fa2 and 32cf9aa.

📒 Files selected for processing (1)
  • packages/job-dispatch/src/job-dispatch.ts (3 hunks)
🔇 Additional comments (2)
packages/job-dispatch/src/job-dispatch.ts (2)

9-9: LGTM: Import added correctly

The import for createReleaseVariables is properly placed and follows the project's import structure.


94-115: 🛠️ Refactor suggestion

Simplify type assertions and bulk updates

The type assertions and filtering for undefined values are redundant since we're working with array indices that match the results array.

Consider simplifying:

-    if (jobsWithResolvedVariables.length > 0) {
      await dispatchJobsQueue.addBulk(
-        jobsWithResolvedVariables
-          .filter((wf): wf is schema.Job => wf !== undefined)
-          .map((wf) => ({
+        jobsWithResolvedVariables.map((wf) => ({
           name: wf.id,
           data: { jobId: wf.id },
         })),
      );

      await this.db
        .update(schema.job)
        .set({ status: JobStatus.InProgress })
        .where(
          inArray(
            schema.job.id,
-            jobsWithResolvedVariables
-              .filter((j): j is schema.Job => j !== undefined)
-              .map((j) => j.id),
+            jobsWithResolvedVariables.map((j) => j.id),
          ),
        );
-    }

Likely invalid or redundant comment.

packages/job-dispatch/src/job-dispatch.ts Outdated Show resolved Hide resolved
packages/job-dispatch/src/job-dispatch.ts Show resolved Hide resolved
@jsbroks jsbroks merged commit 2ab4f61 into main Oct 26, 2024
8 checks passed
@jsbroks jsbroks deleted the zacharyb/eng-250 branch October 26, 2024 07:56
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