-
Notifications
You must be signed in to change notification settings - Fork 11
feat: new env worker #502
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
feat: new env worker #502
Conversation
WalkthroughA new worker for handling "NewEnvironment" events was introduced and integrated into the event-worker system. The worker listens for new environment creation events and triggers recomputation of release targets associated with the new environment. The API logic in both the webservice and API router was updated to enqueue "NewEnvironment" events when appropriate, ensuring that the new worker is invoked after an environment is created. Variable naming was improved for clarity, and the queuing logic was adjusted to distinguish between new and updated environments. Changes
Sequence Diagram(s)sequenceDiagram
participant API_Client
participant Webservice_API
participant Event_Queue
participant Event_Worker
participant Database
API_Client->>Webservice_API: Create Environment Request
Webservice_API->>Database: Upsert Environment
Database-->>Webservice_API: Environment (new or existing)
alt New Environment
Webservice_API->>Event_Queue: Enqueue NewEnvironment event
else Existing Environment
Webservice_API->>Event_Queue: Enqueue UpdateEnvironment event
end
Event_Queue->>Event_Worker: Deliver NewEnvironment event
Event_Worker->>Database: Fetch environment, system, selectors
Event_Worker->>Event_Queue: Enqueue evaluation jobs for release targets
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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)
apps/event-worker/src/workers/new-environment.ts (1)
21-28: Consider adding error handling and logging.The worker implementation is functional but lacks error handling and logging. Consider adding:
- Try/catch block with error logging
- Success logging for better operational visibility
export const newEnvironmentWorker = createWorker( Channel.NewEnvironment, async (job) => { + try { const { data: environment } = job; + console.log(`Processing new environment: ${environment.id}`); const releaseTargets = await recomputeReleaseTargets(environment); + console.log(`Recomputed ${releaseTargets.length} release targets for environment ${environment.id}`); await dispatchEvaluateJobs(releaseTargets); + console.log(`Successfully dispatched evaluation jobs for environment ${environment.id}`); + } catch (error) { + console.error(`Error processing new environment job:`, error); + throw error; // Re-throw to let BullMQ handle the failure + } }, );
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/event-worker/src/workers/index.ts(2 hunks)apps/event-worker/src/workers/new-environment.ts(1 hunks)apps/webservice/src/app/api/v1/environments/route.ts(2 hunks)packages/api/src/router/environment.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/api/src/router/environment.tsapps/event-worker/src/workers/index.tsapps/webservice/src/app/api/v1/environments/route.tsapps/event-worker/src/workers/new-environment.ts
🧬 Code Graph Analysis (3)
packages/api/src/router/environment.ts (2)
packages/db/src/upsert-env.ts (1)
upsertEnv(34-80)packages/events/src/index.ts (1)
getQueue(28-34)
apps/event-worker/src/workers/index.ts (1)
apps/event-worker/src/workers/new-environment.ts (1)
newEnvironmentWorker(21-28)
apps/event-worker/src/workers/new-environment.ts (6)
packages/db/src/schema/environment.ts (1)
environment(59-84)packages/db/src/selectors/index.ts (1)
selector(18-18)packages/db/src/client.ts (1)
db(15-15)packages/db/src/common.ts (1)
takeFirst(9-13)packages/events/src/index.ts (1)
createWorker(10-25)apps/event-worker/src/utils/dispatch-evaluate-jobs.ts (1)
dispatchEvaluateJobs(5-11)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Typecheck
- GitHub Check: Lint
- GitHub Check: build (linux/amd64)
- GitHub Check: build (linux/amd64)
🔇 Additional comments (7)
apps/event-worker/src/workers/index.ts (2)
11-11: Import of the new worker looks good.The import statement for
newEnvironmentWorkeris correctly added.
28-28: The new environment worker is now enabled.The worker is properly registered to handle the
Channel.NewEnvironmentchannel events.packages/api/src/router/environment.ts (1)
271-275: Good use of transaction to ensure atomicity.The transaction ensures that both the environment creation and event queuing happen atomically. Using
getQueue(Channel.NewEnvironment).add(env.id, env)correctly enqueues the new environment for processing by the worker.apps/webservice/src/app/api/v1/environments/route.ts (3)
40-41: Improved variable naming for clarity.Renaming from
channelstoversionChannelsmore accurately describes what the variable contains.
65-65: Updated upsertEnv call with improved variable name.The function call is updated to use the renamed
versionChannelsvariable.
67-77: Good conditional logic for different environment events.The code correctly differentiates between:
- Updating an existing environment (queuing
UpdateEnvironmentevent with old selector)- Creating a new environment (queuing
NewEnvironmentevent)Using
awaitwith queue operations ensures they complete before the transaction finishes.apps/event-worker/src/workers/new-environment.ts (1)
8-19: The release target recomputation logic looks solid.The function correctly:
- Creates a selector compute builder
- Configures it for the environment
- Fetches the system and workspace context
- Recomputes all relevant release targets
Summary by CodeRabbit