Skip to content

feat: Init release upsert in workers#451

Closed
adityachoudhari26 wants to merge 1 commit intomainfrom
init-release-upsert
Closed

feat: Init release upsert in workers#451
adityachoudhari26 wants to merge 1 commit intomainfrom
init-release-upsert

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Apr 4, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced the deployment update process for more reliable creation and updating of release records.
  • Refactor
    • Streamlined the update mechanism for setting release details, reducing complexity and ensuring consistent behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

This pull request enhances deployment management by updating the new deployment worker and simplifying release repository interfaces. The worker now imports additional types from the rule-engine, adjusts its query to include associated system details, and remaps release target data. Simultaneously, the setDesired method signatures in both the repository implementation and its interface have been streamlined to accept a single string parameter instead of an object. These changes refine the process of creating and managing release targets during deployments.

Changes

Files Change Summary
apps/event-worker/src/workers/new-deployment-version.ts Added new imports (ReleaseTargetIdentifier, DatabaseReleaseRepository), updated deployment query to include system details, renamed variable to releaseTargetInserts, and enhanced logic to create and upsert release targets.
packages/rule-engine/src/releases/repositories/release-repository.ts
.../types.ts
Modified setDesired method signature in both the repository implementation and its interface to accept a single string parameter (desiredReleaseId) rather than an object parameter.

Sequence Diagram(s)

sequenceDiagram
    participant Worker as newDeploymentVersionWorker
    participant DB as Database
    participant Repo as DatabaseReleaseRepository

    Worker->>DB: Query deployment with system details
    DB-->>Worker: Return deployment data
    Worker->>Worker: Map resources to releaseTargetInserts
    loop For each release target
        Worker->>Repo: Create instance with ReleaseTargetIdentifier
        Repo->>Repo: Upsert release with latest variables
        Repo-->>Worker: Return inserted release record
        Worker->>Repo: If newest, call setDesired(desiredReleaseId)
    end
Loading

Possibly related PRs

Suggested reviewers

  • jsbroks

Poem

I'm a bunny in the code, light on my feet,
Hopping through deployments with a rhythmic beat.
Release targets revamped, like carrots in a row,
Simplified methods make my workflow glow.
With a twitch of my whiskers, I cheer this delight,
CodeRabbit's changes make my world so bright!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2ad69bd and 6a27e34.

📒 Files selected for processing (3)
  • apps/event-worker/src/workers/new-deployment-version.ts (2 hunks)
  • packages/rule-engine/src/releases/repositories/release-repository.ts (1 hunks)
  • packages/rule-engine/src/releases/repositories/types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{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...

**/*.{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.

  • packages/rule-engine/src/releases/repositories/release-repository.ts
  • apps/event-worker/src/workers/new-deployment-version.ts
  • packages/rule-engine/src/releases/repositories/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
🔇 Additional comments (13)
packages/rule-engine/src/releases/repositories/types.ts (1)

29-29:

Details

✅ Verification successful

Simplified interface for setDesired.

This change makes the interface easier to use by taking a single string parameter. Please verify that all references to setDesired have been updated accordingly.

Below is a script to locate all usages of setDesired( within the repository, ensuring they pass only one parameter:


🏁 Script executed:

#!/bin/bash
rg -A 3 "setDesired("

Length of output: 96


Below is a revised review comment that highlights the need to re-run the verification with a corrected search pattern. In the updated comment, the regex for identifying setDesired references properly escapes the parenthesis so that you can verify that all usages now match the new, simplified interface.

Updated Verification Needed for Simplified setDesired Interface

It appears the previous verification command produced a regex error due to an unescaped parenthesis. Please re-run the search using the updated shell script below to ensure that all references to setDesired have been updated to use only one parameter:

  • File under review: packages/rule-engine/src/releases/repositories/types.ts (line 29)
  • Action: Search the repository for occurrences of setDesired using an escaped parenthesis:

This will help verify that:

  • All invocations of setDesired now correctly pass a single string parameter.
  • There are no outdated or mismatched usages remaining.

Please run the above script and confirm that the changes are fully consistent across the codebase.


🏁 Script executed:

#!/bin/bash
rg -A 3 "setDesired\("

Length of output: 1038


Verified: Simplified setDesired Interface is Consistently Applied

The verification script confirms that all references to setDesired across the repository now use the simplified interface with a single string parameter. Specifically:

  • Interface Definition:

    • packages/rule-engine/src/releases/repositories/types.ts correctly defines the interface as setDesired(desiredReleaseId: string): Promise<void>;.
  • Implementation & Usage:

    • packages/rule-engine/src/releases/repositories/release-repository.ts implements the function accepting a single parameter.
    • apps/event-worker/src/workers/new-deployment-version.ts correctly invokes setDesired with only one argument (release.id).

No discrepancies were found.

packages/rule-engine/src/releases/repositories/release-repository.ts (1)

183-187: Method signature alignment with simplified interface.

Changing from an object parameter to a single string parameter keeps the repository consistent with the updated interface, and the .set({ desiredReleaseId }) call aligns properly with the new approach. No issues found.

apps/event-worker/src/workers/new-deployment-version.ts (11)

2-2: New import of ReleaseTargetIdentifier.

Importing ReleaseTargetIdentifier is appropriate for constructing release target data. No concerns.


9-9: DatabaseReleaseRepository import.

Bringing in DatabaseReleaseRepository facilitates the new deployment version logic. Looks good.


61-61: Refined include in query.

Fetching system data alongside the deployment for later use is clear and consistent with the new logic.


68-72: Building releaseTargetInserts.

Mapping resources into release target inserts is straightforward. No issues here.


74-79: Inserting release targets with onConflictDoNothing.

Using onConflictDoNothing avoids duplicate creation. This is a valid approach if ignoring existing records is desired.


80-82: Destructuring system and workspaceId.

Straightforward extraction of key properties. Looks good.


83-90: Creating repository instances and forming ReleaseTargetIdentifier.

Attaching workspaceId to the release target for repository creation is logical. The constructed identifier nicely encapsulates deployment, environment, and resource info.


92-99: Upserting releases for each target.

The upsert operation, combined with fetching the latest variables, properly ensures each target has a release. No concerns.


100-101: Ensuring the newly created release is the newest.

This conditional check prevents overwriting a more recent release if concurrency or a race condition occurs. LGTM.


103-104: Invoking setDesired with the new signature.

Consistently passing just the release ID aligns with the updated method signature in the repository.


106-106: Awaiting all promises concurrently.

Resolving all repository operations in parallel is efficient. No issues.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@adityachoudhari26 adityachoudhari26 deleted the init-release-upsert branch May 5, 2025 19:49
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.

1 participant