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

Notion schema fix and Cron schedule change #2793

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

tomer-shvadron
Copy link
Collaborator

@tomer-shvadron tomer-shvadron commented Oct 22, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new operator, IN_CASE_INSENSITIVE, enhancing the rule schema's capabilities for case-insensitive operations.
    • Expanded the riskLevel categorization to include a new value, high, for more nuanced risk assessments.
  • Bug Fixes

    • Updated the cron job frequency from every minute to every hour for improved resource management.
  • Refactor

    • Streamlined import statements for better organization in the rule engine package.
    • Refactored function declarations to modern syntax without changing functionality.
  • Tests

    • Enhanced unit tests to validate the new IN_CASE_INSENSITIVE operator and improved error handling for various scenarios in the rule engine.

Copy link

changeset-bot bot commented Oct 22, 2024

⚠️ No Changeset found

Latest commit: d0b209a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes in this pull request primarily involve the addition of a new constant IN_CASE_INSENSITIVE to the OPERATION object and its inclusion in the OPERATIONS array. Additionally, the schemas.ts file has been updated to centralize imports and refactor the getValues function. The RiskRulesPluginParams interface has been modified to allow for a new riskLevel value, and the NotionRiskRuleRecordSchema has been updated to include this new value. The cron job frequency in the OngoingMonitoringCron class has also been adjusted from every minute to every hour.

Changes

File Change Summary
packages/common/src/rule-engine/operators/enums.ts Added constant IN_CASE_INSENSITIVE to OPERATION and included it in the OPERATIONS array.
packages/common/src/rule-engine/rules/schemas.ts Updated import paths for OPERATION and OPERATOR; refactored getValues to an arrow function; added IN_CASE_INSENSITIVE operator to RuleSchema.
packages/workflow-core/src/lib/plugins/common-plugin/types.ts Updated riskLevel property type to include 'high'.
services/workflows-service/prisma/data-migrations Updated subproject commit hash.
services/workflows-service/src/rule-engine/risk-rule.service.intg.test.ts Changed import path for NotionService from relative to absolute.
services/workflows-service/src/rule-engine/risk-rule.service.ts Updated NotionRiskRuleRecordSchema to include 'high' in the risk level enum.
services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.ts Changed cron job frequency from every minute to every hour.

Possibly related PRs

  • RiskRuleService with Notion #2468: The addition of the IN_CASE_INSENSITIVE operator in the RiskRuleService is directly related to the new constant IN_CASE_INSENSITIVE introduced in the main PR, as both involve updates to the rule engine's operations.
  • feature/risk_rule_logic #2472: This PR also discusses the rule engine and includes modifications that may relate to the handling of operators, including the new IN_CASE_INSENSITIVE operator.
  • Added NOT EQUALS, IN and NOT_IN operations to rule engine #2512: This PR adds the NOT_EQUALS operation to the rule engine, which is relevant as it pertains to the same context of modifying operations within the rule engine.
  • Added missing risk rules operations #2520: This PR updates the risk-rule.service.ts file to include new operations like NOT_EQUALS, EXISTS, IN, and NOT_IN, which are closely related to the changes made in the main PR regarding the operations.
  • feat: add new rules #2707: The changes in this PR involve the OngoingMonitoringCron, which may relate to the broader context of rule evaluations and operations, especially if they involve the new IN_CASE_INSENSITIVE operator.
  • Ongoing cron - not running for incomplete reports #2783: This PR modifies the OngoingMonitoringCron to ensure that only completed reports are processed, which could relate to the operational logic introduced in the main PR regarding how operations are evaluated in the rule engine.

Suggested reviewers

  • liorzam
  • alonp99

🐰 In the meadow where changes bloom,
New constants rise, dispelling gloom.
With schemas updated and risks refined,
A cron job's pace, now redefined.
Let's hop along, with joy we sing,
For every change, new hopes they bring! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a53e715 and d0b209a.

📒 Files selected for processing (2)
  • services/workflows-service/src/rule-engine/core/test/rule-engine.unit.test.ts (1 hunks)
  • services/workflows-service/src/rule-engine/risk-rule.service.intg.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • services/workflows-service/src/rule-engine/risk-rule.service.intg.test.ts
🧰 Additional context used
🔇 Additional comments (1)
services/workflows-service/src/rule-engine/core/test/rule-engine.unit.test.ts (1)

122-128: Updated error message includes new operator 'IN_CASE_INSENSITIVE'

The inline snapshot now correctly reflects the addition of the IN_CASE_INSENSITIVE operator. This ensures that the error message provides an accurate list of valid operators when an unknown operator is encountered.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

🧹 Outside diff range and nitpick comments (1)
services/workflows-service/src/rule-engine/risk-rule.service.intg.test.ts (1)

Line range hint 1-46: Consider adding tests for the new 'high' risk level.

The AI summary mentions that a new 'high' risk level was added to the NotionRiskRuleRecordSchema. However, the existing tests in this file don't appear to cover this new risk level explicitly.

Consider adding a new test case to validate the behavior of the findAll method when dealing with records that have the 'high' risk level. This will ensure that the new risk level is properly handled and validated.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5448ecd and a53e715.

📒 Files selected for processing (7)
  • packages/common/src/rule-engine/operators/enums.ts (2 hunks)
  • packages/common/src/rule-engine/rules/schemas.ts (2 hunks)
  • packages/workflow-core/src/lib/plugins/common-plugin/types.ts (1 hunks)
  • services/workflows-service/prisma/data-migrations (1 hunks)
  • services/workflows-service/src/rule-engine/risk-rule.service.intg.test.ts (1 hunks)
  • services/workflows-service/src/rule-engine/risk-rule.service.ts (1 hunks)
  • services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • services/workflows-service/prisma/data-migrations
🧰 Additional context used
🔇 Additional comments (7)
packages/common/src/rule-engine/operators/enums.ts (2)

28-28: LGTM: New operation added to OPERATIONS array.

The IN_CASE_INSENSITIVE operation has been correctly added to the OPERATIONS array, maintaining consistency between the OPERATION object and the OPERATIONS array.


12-12: LGTM: New case-insensitive operation added.

The addition of IN_CASE_INSENSITIVE to the OPERATION object is consistent with the existing pattern and naming convention. This new operation will likely enable case-insensitive matching in the rule engine.

To ensure this change is properly integrated, let's verify its usage:

✅ Verification successful

Verified: New case-insensitive operation is properly integrated.

The IN_CASE_INSENSITIVE operation is correctly added to the OPERATION object and is actively used in the schemas.ts file. This ensures that case-insensitive matching is effectively supported in the rule engine.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of the new IN_CASE_INSENSITIVE operation
# Expected: Find references to this new operation in other parts of the codebase

rg "IN_CASE_INSENSITIVE" --type ts

Length of output: 320

packages/common/src/rule-engine/rules/schemas.ts (3)

83-87: LGTM! New operator enhances rule engine capabilities.

The addition of the IN_CASE_INSENSITIVE operator to the RuleSchema expands the rule engine's capabilities to handle case-insensitive operations.

Please ensure that this new operator is properly handled in the rule engine implementation. Run the following script to check for its usage and implementation:

#!/bin/bash
# Description: Check implementation and usage of IN_CASE_INSENSITIVE operator

# Test: Search for IN_CASE_INSENSITIVE usage in the codebase
echo "Searching for IN_CASE_INSENSITIVE usage:"
rg -A 5 'IN_CASE_INSENSITIVE'

# Test: Check for any switch statements or if-else blocks that should include this new operator
echo "Checking for switch statements or if-else blocks that might need updating:"
ast-grep --pattern $'switch ($_) {
  $$$
}' | rg -A 10 'OPERATION|operator'

ast-grep --pattern $'if ($_ === OPERATION.$_) {
  $$$
} else if' | rg -A 10 'OPERATION|operator'

5-6: LGTM! Centralized imports improve maintainability.

The change to import OPERATION, OPERATOR, and other schemas directly from '@/rule-engine' centralizes the imports and potentially improves maintainability.

Please verify that '@/rule-engine' is correctly configured in the project. Run the following script to check the import path:

Also applies to: 13-13


15-17: LGTM! Function refactoring aligns with modern practices.

The refactoring of getValues to an arrow function improves code consistency with modern JavaScript practices.

Please verify that this change doesn't affect any code relying on hoisting of the getValues function. Run the following script to check its usage:

✅ Verification successful

LGTM! Function refactoring aligns with modern practices.

The refactoring of getValues to an arrow function maintains functionality and ensures consistency within the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage of getValues function

# Test: Search for getValues usage in the codebase
rg -A 5 'getValues\s*\('

Length of output: 1777


Script:

#!/bin/bash
# Description: Verify usage of the getValues function in the codebase

# Search for getValues function calls
rg -A 5 'getValues\s*\('

Length of output: 902


Script:

#!/bin/bash
# Description: Comprehensive search for getValues function usage in the codebase

# Search for getValues function definitions and calls using word boundaries
rg --word-regexp 'getValues\b' -A 5

Length of output: 1418

packages/workflow-core/src/lib/plugins/common-plugin/types.ts (1)

78-78: LGTM! Verify impact on dependent systems.

The addition of 'high' to the riskLevel type provides more granularity in risk assessment, which is a positive change. However, ensure that all systems consuming this risk level information are updated to handle the new 'high' value correctly.

To verify the impact, run the following script:

Please review the output to ensure all occurrences are updated to handle the new 'high' risk level.

✅ Verification successful

Verified Impact on Dependent Systems

The addition of 'high' to the riskLevel type has been thoroughly reviewed across the codebase. All usages of riskLevel already account for the 'high' value, ensuring no issues with dependent systems.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usages of riskLevel in the codebase
# Expected result: List of files using riskLevel, to be manually reviewed for necessary updates

# Search for riskLevel usage
echo "Files using riskLevel:"
rg "riskLevel" --type ts

# Search for specific risk level values
echo "\nFiles using specific risk level values:"
rg -e "'critical'" -e "'high'" -e "'moderate'" -e "'positive'" --type ts

Length of output: 19942

services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.ts (1)

33-33: Cron schedule change approved, but verify impact.

The change from running every minute to every hour aligns with the PR objectives and could potentially improve system performance by reducing server load. However, it's important to verify that this reduced frequency doesn't negatively impact the timely processing of ongoing monitoring tasks.

To ensure this change doesn't introduce unexpected behavior, please run the following verification steps:

  1. Check if there are any time-sensitive operations in the handleCron method that might be affected by the hourly schedule.
  2. Verify that the new schedule aligns with the business requirements for ongoing monitoring.
  3. Monitor the system after deployment to ensure that the reduced frequency doesn't cause any backlogs or delays in processing.

@tomer-shvadron tomer-shvadron merged commit 028dcb3 into dev Oct 22, 2024
10 checks passed
@tomer-shvadron tomer-shvadron deleted the chore/tomer/notion-schema-update branch October 22, 2024 15:07
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.

3 participants