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

fix: Check if removed from entire system #226

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Nov 22, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new filter for resources not present in a specified system, enhancing resource dispatching logic.
    • Updated event dispatching for removed resources to accept a structured environment object.
  • Bug Fixes

    • Improved error handling and logging for resource dispatching processes.
  • Documentation

    • Updated method signatures for better clarity on function parameters and return types.

Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

Walkthrough

The pull request introduces several modifications to the dispatch-resource.ts, upsert.ts, and utils.ts files within the job dispatch package. Key changes include the addition of the getNotInSystemFilter function, which retrieves filters for resources not present in a specified system. The dispatchEventsForRemovedResources function is updated to accept an environment object instead of just an ID, enhancing data handling. Additionally, the upsertResources function now passes an environment object to the event dispatch function, and the getEnvironmentsByResourceWithIdentifiers function includes a new systemId field in its query.

Changes

File Path Change Summary
packages/job-dispatch/src/resource/dispatch-resource.ts - Added `async getNotInSystemFilter(systemId: string): Promise<ResourceCondition
packages/job-dispatch/src/resource/upsert.ts - Updated call to dispatchEventsForRemovedResources to pass the entire environment object instead of just IDs.
packages/job-dispatch/src/resource/utils.ts - Modified getEnvironmentsByResourceWithIdentifiers to include systemId in the query selection.

Possibly related PRs

Suggested reviewers

  • jsbroks

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.

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

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

161-182: Consider adding a log message when no filters are found

In the getNotInSystemFilter function, if filters.length === 0, the function returns null without any log message. For better debugging and traceability, consider adding a log statement to indicate that no applicable filters were found for the system.

Apply this diff to add the log message:

 if (filters.length === 0) return null;

+ log.info("No resource filters found in environments for system", { systemId });

205-208: Refine log message for clarity when 'notInSystemFilter' is null

The log message "No system found for environment" may be misleading when notInSystemFilter is null because it could be due to the absence of applicable filters rather than the system not being found. To improve clarity, consider updating the log message to reflect the actual reason.

Apply this diff to update the log message:

 if (notInSystemFilter == null) {
-   log.warn("No system found for environment", { envId });
+   log.warn("No applicable resource filters found for system", { envId, systemId });
    return;
 }

193-196: Ensure consistent parameter documentation

In the dispatchEventsForRemovedResources function signature, ensure that the JSDoc comments accurately reflect the updated parameters. The parameter env should be documented, and any outdated references to envId should be updated.

Apply this diff to update the documentation:

 /**
  * Dispatches hook events for resources that were removed from an environment
  * @param db - Database transaction
  * @param resourceIds - IDs of the resources that were removed
- * @param envId - ID of the environment the resources were removed from
+ * @param env - Object containing the environment ID and system ID
  */
 export const dispatchEventsForRemovedResources = async (
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4f2532 and 035d21b.

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

80-80: LGTM! The addition of systemId supports system-wide resource removal checks.

The change to include systemId in the environment selection is aligned with the PR's objective of checking if resources are removed from the entire system.

Let's verify how this systemId is used in related files:

✅ Verification successful

LGTM! The systemId addition is correctly integrated with the system-wide resource removal checks.

The search results confirm that the systemId is properly used in the resource removal workflow:

  • In dispatch-resource.ts, it's used by getNotInSystemFilter to check if resources are removed from the entire system
  • The dispatchEventsForRemovedResources function uses this systemId to verify system-wide resource removal before dispatching events
  • The change is integrated with environment queries and joins across the codebase, maintaining data consistency
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of systemId in resource removal logic
# Expected: Find references showing how systemId is used to check system-wide resource removal

# Search for functions that use systemId in resource removal context
rg -A 5 "systemId.*resource.*remov" 

# Search for the dispatchEventsForRemovedResources function that was updated
ast-grep --pattern 'function dispatchEventsForRemovedResources($_) {
  $$$
}'

Length of output: 117


Script:

#!/bin/bash
# Let's try a broader search to understand the context better

# Search for systemId usage in the job-dispatch package
rg -A 5 "systemId" packages/job-dispatch/

# Search for functions related to resource removal
rg -A 5 "resource.*remov|remov.*resource" packages/job-dispatch/

# Look for the getNotInSystemFilter function mentioned in the PR summary
ast-grep --pattern 'function getNotInSystemFilter($_) {
  $$$
}'

Length of output: 20567

packages/job-dispatch/src/resource/upsert.ts (1)

128-128: LGTM! The change aligns with the PR objective.

The update to pass the full environment object instead of just the ID enables checking if resources are removed from the entire system.

Let's verify the integration with related changes:

✅ Verification successful

Function signature and usage are correctly aligned across the codebase

The verification confirms:

  • The dispatchEventsForRemovedResources function correctly expects the full environment object with both id and systemId properties
  • The function call in upsert.ts passes the complete env object
  • The environment-related utilities in utils.ts handle the systemId field
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function signature change and its usage
# Expected: The function should accept full environment object in all implementations

# Check the function signature in dispatch-resource.ts
rg -A 2 "dispatchEventsForRemovedResources.*=.*async" 

# Check all calls to this function
rg "dispatchEventsForRemovedResources\(" 

# Verify environment query includes systemId
rg "getEnvironmentsByResourceWithIdentifiers.*select"

Length of output: 531


Script:

#!/bin/bash
# Let's check the complete function signature and implementation
ast-grep --pattern 'const dispatchEventsForRemovedResources = async ($$$) {
  $$$
}'

# Check the environment parameter type and usage
rg -B 2 -A 5 "dispatchEventsForRemovedResources.*=.*async"

# Check environment-related queries in utils
fd utils.ts --exec rg -l "systemId.*environment"

Length of output: 950

@adityachoudhari26 adityachoudhari26 merged commit 586c68f into main Nov 22, 2024
8 of 9 checks passed
@adityachoudhari26 adityachoudhari26 deleted the check-if-removed-from-system branch November 22, 2024 23:22
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