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

New Resource worker #450

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

j7m4
Copy link
Contributor

@j7m4 j7m4 commented Apr 4, 2025

  • new worker framework, wip
  • ignore sqltools connection files

Summary by CodeRabbit

  • New Features

    • Introduced a new processing workflow to enhance the management of resource creation and release operations.
    • Expanded event handling to support dynamic environment resource updates and improved release coordination.
  • Chores

    • Updated workspace configuration to exclude temporary session files, ensuring a cleaner development environment.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

This pull request updates multiple files to extend resource handling capabilities. The changes include an update to the .gitignore file to ignore .session.sql files for VSCode, and enhancements in the event-worker module by adding a new resource worker. Additionally, the changes extend channel enumerations and type mappings in the events package, introduce a new interface in the release manager for resource releases, and add a new event in the validators package. Overall, these updates integrate a new resource workflow into the system.

Changes

File(s) Change Summary
.gitignore Added a new entry *.session.sql under a # VSCode related section.
apps/event-worker/src/workers/index.ts
apps/event-worker/src/workers/new-resource.ts
Introduced a new worker (newResourceWorker), with a new import from ./new-resource.js and an updated workers mapping to include [Channel.NewResource]: newResourceWorker.
packages/events/src/types.ts Added a new enum value NewResource (with string value "new-resource") and updated the ChannelMap type to map Channel.NewResource to typeof schema.resource.$inferSelect.
packages/release-manager/src/resource/types.ts Added a new interface ResourceRepository with methods: getLatest, create, createForVersion, upsert, and setDesired for managing resource releases.
packages/validators/src/events/index.ts Added a new enum value ReleaseNewEnvResource, a new event object releaseNewEnvResourceEvent (with environmentId and resourceId properties), and a corresponding inferred type.

Sequence Diagram(s)

sequenceDiagram
    participant J as Job Queue
    participant W as newResourceWorker
    participant DB as Database
    participant RM as Release Manager
    participant Q as Evaluation Queue

    J->>W: Submit new resource job
    W->>DB: Query environments & deployments
    DB-->>W: Return query results
    W->>DB: Check for existing release targets (with onConflictDoNothing)
    W->>RM: Upsert and mark release as desired
    RM-->>W: Confirm release update
    W->>Q: Enqueue evaluation job data in bulk
    W->>W: Log operation details
Loading

Poem

I'm a bouncy rabbit in a code-filled burrow,
Hopping through changes with a joyful glow.
New workers, enums, and schemas so bright,
Make our code garden a wondrous delight.
Carrots and commits in a joyful parade—
Here's to fresh code and the progress we've made! 🥕
Keep on hopping, code friends!

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

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

🧹 Nitpick comments (1)
apps/event-worker/src/workers/new-resource.ts (1)

70-75: Confirm error handling when calling ReleaseManager.

Currently, if releaseManager.upsertVersionRelease fails due to an invalid version or database error, the worker may fail silently or re-attempt indefinitely. Ensure that job failure or retry logic is clear for these scenarios.

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

📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • apps/event-worker/src/workers/index.ts (2 hunks)
  • apps/event-worker/src/workers/new-resource.ts (1 hunks)
  • packages/events/src/types.ts (2 hunks)
  • packages/release-manager/src/resource/types.ts (1 hunks)
  • packages/validators/src/events/index.ts (2 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.

  • apps/event-worker/src/workers/index.ts
  • packages/validators/src/events/index.ts
  • packages/release-manager/src/resource/types.ts
  • packages/events/src/types.ts
  • apps/event-worker/src/workers/new-resource.ts
🧬 Code Definitions (1)
apps/event-worker/src/workers/index.ts (1)
apps/event-worker/src/workers/new-resource.ts (1)
  • newResourceWorker (8-90)
🔇 Additional comments (10)
.gitignore (1)

62-63: LGTM: Good addition to ignore VSCode SQL session files.

The addition of this rule to ignore .session.sql files is a good practice for keeping SQL tool connection files out of version control.

apps/event-worker/src/workers/index.ts (2)

5-5: LGTM: Good import for the new resource worker.

The import statement correctly references the new worker module with the proper file extension.


20-20: LGTM: Proper integration of new resource worker.

The new resource worker is correctly mapped to the corresponding Channel.NewResource enum value, maintaining consistency with the existing pattern for worker registration.

packages/events/src/types.ts (2)

16-16: LGTM: New resource channel properly defined.

The new channel enum value follows the existing naming convention and is appropriately placed in the enum list.


30-30: LGTM: Proper type mapping for new resource channel.

The type mapping for the new resource channel correctly uses the resource schema's inferred select type, which is consistent with the pattern used for other entity channels.

packages/validators/src/events/index.ts (2)

13-13: LGTM: New environment resource event channel added.

The new enum value for environment resource events follows the existing naming convention and fits well with the related event types.


57-61: LGTM: Event schema properly defined with required fields.

The new event schema correctly defines the structure with the required environment and resource IDs. The type export follows the established pattern in this file.

apps/event-worker/src/workers/new-resource.ts (2)

60-62: Validate the schema for unique constraints before using onConflictDoNothing().

Using onConflictDoNothing() is effective to avoid duplicate inserts if there is a suitable unique constraint or index on the table. Verify that such constraints exist on schema.releaseTarget to ensure idempotence.


66-68: Handle the case where deployment_version is not found.

When looking up deployment_version.id via deployments.find(...), the code defaults to "unknown" if no match is found. Ensure subsequent operations can handle an "unknown" version gracefully or consider throwing an error, based on your desired logic.

packages/release-manager/src/resource/types.ts (1)

4-42: Interface definitions look solid.

The new ResourceRepository interface is well-documented and clarifies important release operations. Consider adding usage examples or references to these methods in the doc comments if future contributors might need extra guidance.

Comment on lines +32 to +56
for (const { environment } of environments) {
for (const { deployment } of deployments) {
const res = await db.select().from(schema.resource)
.where(
and(
eq(schema.resource.id, resource.id),
schema.resourceMatchesMetadata(
db,
environment.resourceSelector,
),
schema.resourceMatchesMetadata(
db,
deployment.resourceSelector,
),
),
).then(takeFirstOrNull);
if (res != null) {
releaseRepos.push({
resourceId: res.id,
environmentId: environment.id,
deploymentId: deployment.id,
});
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider optimizing the nested loops for performance.

Running a database query within nested loops can result in performance bottlenecks, especially if the number of environments and deployments grows. Consider refactoring this into a single combined query or a batched approach to reduce the number of round trips to the database.

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