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

Ongoing cron - not running for incomplete reports #2783

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

tomer-shvadron
Copy link
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Enhanced status management for business reports, ensuring only completed reports are processed in ongoing monitoring.
  • Bug Fixes

    • Improved logging clarity regarding the absence of initial reports and the status of the last report.
  • Refactor

    • Made conditions for logging and processing more explicit while preserving the logic for skipping ongoing reports.
  • Tests

    • Expanded test coverage for the ongoing monitoring service, including checks for incomplete reports.

Copy link

changeset-bot bot commented Oct 15, 2024

⚠️ No Changeset found

Latest commit: bd68393

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 15, 2024

Walkthrough

The changes in this pull request focus on the OngoingMonitoringCron class within the ongoing-monitoring.cron.ts file. Key modifications include the addition of the BusinessReportStatus import from the @prisma/client package, updates to the handleCron method to check for the lastReceivedReport.status, and refined logging statements. These adjustments ensure that only completed reports are processed while maintaining the existing logic for skipping ongoing reports. Additionally, the testing file ongoing-monitoring.cron.intg.test.ts has been updated to enhance test coverage for the new functionalities.

Changes

File Path Change Summary
services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.ts - Added import for BusinessReportStatus from @prisma/client.
- Updated handleCron to check lastReceivedReport.status.
- Refined logging statements for clarity.
services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.intg.test.ts - Expanded import for @prisma/client to include BusinessReportStatus and BusinessReportType.
- Added BusinessReportService to the testing module.
- Introduced a new test case for incomplete last reports.
- Updated mock implementations for findMany and added createBusinessReportAndTriggerReportCreation method.

Possibly related PRs

  • blokh/feat/business report alerts #2311: This PR adds the BusinessReportStatus import and modifies the BusinessReport model, which is directly related to the changes made in the OngoingMonitoringCron class regarding report status management.
  • feat: business Report in Backoffice updates #2450: This PR includes updates to the BusinessReportService and BusinessReportRepository, which are relevant as they interact with the business report functionalities that the OngoingMonitoringCron class relies on.
  • Ongoing monitoring #2743: This PR enhances the OngoingMonitoringCron class, particularly in the areas of report generation and logging, which aligns closely with the changes made in the main PR.
  • feat: build fix try 1 #2750: This PR modifies the OngoingMonitoringCron class, specifically adjusting the cron job frequency and maintaining the logic for processing ongoing reports, which is directly related to the main PR's changes.
  • Additional swagger documentations #2767: This PR improves logging within the OngoingMonitoringCron class, enhancing the clarity of log messages related to ongoing monitoring, which is a focus of the main PR.

Suggested reviewers

  • MatanYadaev
  • alonp99

🐇 In the meadow where reports do play,
A cron job checks both night and day.
With statuses clear, we skip the rest,
Only completed reports are the best!
So hop along, let the logs be bright,
Ongoing monitoring, a joyful sight! 🌼


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.

@tomer-shvadron tomer-shvadron enabled auto-merge (squash) October 16, 2024 09:12
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 (2)
services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.intg.test.ts (2)

70-99: LGTM: New test case added for incomplete business reports.

The new test case effectively verifies that an ongoing report is not created when the last business report is incomplete. This aligns well with the new functionality to handle different report statuses.

A minor suggestion for improved clarity:

Consider adding a comment explaining the significance of the 30-day difference in the mock data's createdAt and updatedAt dates. This would help other developers understand the test setup more quickly.

 createdAt: new Date(new Date().setDate(new Date().getDate() - 31)),
 updatedAt: new Date(new Date().setDate(new Date().getDate() - 30)),
+// Comment: These dates simulate a report created 31 days ago and last updated 30 days ago

143-154: LGTM: Mock implementation updated to support new test case.

The changes to the BusinessReportService mock, including the updated findMany implementation and the addition of createBusinessReportAndTriggerReportCreation, align well with the new test case for handling incomplete reports.

A minor suggestion for consistency:

Consider using the BusinessReportStatus enum for the status field in the mock data to maintain consistency with the imported types:

-status: BusinessReportStatus.in_progress,
+status: BusinessReportStatus.IN_PROGRESS,

This assumes that the enum values are in uppercase, which is a common convention. Please adjust accordingly if the actual enum values are different.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 44f57f4 and bd68393.

📒 Files selected for processing (1)
  • services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.intg.test.ts (7 hunks)
🧰 Additional context used
🔇 Additional comments (4)
services/workflows-service/src/workflow/cron/ongoing-monitoring.cron.intg.test.ts (4)

7-7: LGTM: Import statement updated to support new functionality.

The addition of BusinessReportStatus and BusinessReportType imports aligns with the new functionality for handling different report statuses and types in the OngoingMonitoringCron service.


23-23: LGTM: Test setup updated to include BusinessReportService.

The addition of businessReportService and its initialization in the beforeEach setup is consistent with the new functionality for handling business reports. This ensures that the service is properly mocked and available for all test cases.

Also applies to: 43-43


118-121: LGTM: Mock implementation simplified, but clarification needed.

The mock implementation for createOrUpdateWorkflowRuntime has been simplified to always resolve with true. While this change is acceptable, it's not immediately clear how it relates to the new functionality for handling business reports.

Could you please clarify the reasoning behind this change? Is it related to the new business report functionality, or is it a separate improvement?


Line range hint 1-248: Overall assessment: Well-implemented changes with good test coverage.

The changes to this test file effectively support the new functionality for handling business reports and their statuses in the OngoingMonitoringCron service. The addition of a new test case for incomplete reports and the updates to mock implementations enhance the overall test coverage.

A few minor suggestions have been made for improved clarity and consistency, but these are not critical issues. The code changes appear to be well-thought-out and align with the intended functionality described in the AI-generated summary.

@tomer-shvadron tomer-shvadron merged commit 0a934ec into dev Oct 16, 2024
10 checks passed
@tomer-shvadron tomer-shvadron deleted the chore/tomer/ongoing-cron-incomplete-report branch October 16, 2024 09:19
@Omri-Levy Omri-Levy mentioned this pull request Nov 4, 2024
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