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

Nc feat/cleanup #8508

Merged
merged 7 commits into from
May 23, 2024
Merged

Nc feat/cleanup #8508

merged 7 commits into from
May 23, 2024

Conversation

dstala
Copy link
Member

@dstala dstala commented May 17, 2024

Change Summary

Provide summary of changes with issue number if any.

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

Copy link
Contributor

coderabbitai bot commented May 17, 2024

Warning

Rate Limit Exceeded

@o1lab has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 49 minutes and 30 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between becca55 and 2dbddf7.

Walkthrough

The recent updates to the NocoDB project revolve around enhancing job processing capabilities and improving Redis integration. Key changes include introducing a new CleanUp job type, implementing methods like sourceCleanup, transitioning from JobsRedisService to JobsRedis for Redis interactions, adding a CleanUpProcessor class for workspace and base cleanup tasks, and refactoring the NcConnectionMgrv2 class for better connection management.

Changes

File Path Change Summary
packages/nocodb/src/interface/Jobs.ts Added CleanUp to JobTypes enum.
packages/nocodb/src/models/Source.ts Added imports for JobsRedis and InstanceCommands, introduced sourceCleanup method.
packages/nocodb/src/modules/jobs/fallback/jobs.service.ts Implemented OnModuleInit in JobsService, added onModuleInit method.
packages/nocodb/src/modules/jobs/jobs.controller.ts Updated usage to JobsRedis, modified methods for async handling.
packages/nocodb/src/modules/jobs/jobs.module.ts Removed JobsRedisService from providers list.
packages/nocodb/src/modules/jobs/jobs/clean-up/clean-up.processor.ts Introduced CleanUpProcessor class for cleanup tasks.
packages/nocodb/src/modules/jobs/redis/jobs-redis.ts Added methods for worker count and command emission in JobsRedis.
packages/nocodb/src/modules/jobs/redis/jobs.service.ts Refactored to use JobsRedis directly, updated methods.
packages/nocodb/src/utils/common/NcConnectionMgrv2.ts Renamed delete to deleteAwait, added deleteConnectionRef method.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 9

Out of diff range and nitpick comments (4)
packages/nocodb/src/modules/jobs/redis/jobs.service.ts (1)

33-33: Add comments to clarify the conditions under which the queue is toggled, especially the significance of the environment variables.

packages/nocodb/src/modules/jobs/jobs.module.ts (1)

63-63: Document the impact of environment variables on module configuration to aid in understanding and maintaining the code.

packages/nocodb/src/modules/jobs/jobs.controller.ts (2)

[!TIP]
Codebase Verification

Lack of Error Handling in Redis Subscription Callback

The search results indicate that there are no try-catch blocks or explicit error handling mechanisms within the subscribe method in jobs.controller.ts.

To ensure robust error handling, it is recommended to wrap the callback function of the subscribe method in a try-catch block. This will help in catching any potential errors and handling them appropriately.

Recommended Changes:

  • Add a try-catch block around the callback function in the subscribe method to handle any errors that may occur during the execution of the callback.

Example:

if (JobsRedis.available) {
  await JobsRedis.subscribe(jobId, async (data) => {
    try {
      if (this.jobRooms[jobId]) {
        this.jobRooms[jobId].listeners.forEach((res) => {
          if (!res.headersSent) {
            res.send({
              status: 'refresh',
            });
          }
        });
      }

      const cmd = data.cmd;
      delete data.cmd;
      switch (cmd) {
        case JobEvents.STATUS:
          if ([JobStatus.COMPLETED, JobStatus.FAILED].includes(data.status)) {
            await JobsRedis.unsubscribe(jobId);
            delete this.jobRooms[jobId];
            this.closedJobs.push(jobId);
            setTimeout(() => {
              this.closedJobs = this.closedJobs.filter((j) => j !== jobId);
            }, POLLING_INTERVAL * 2);
          }
          break;
      }
    } catch (error) {
      // Handle the error appropriately
      console.error(`Error handling job event for jobId ${jobId}:`, error);
    }
  });
}

Locations to Update:

  • packages/nocodb/src/modules/jobs/jobs.controller.ts (Lines 88-95)

Category:

Analysis chain

Line range hint 91-110: Verify the logic for managing job event listeners and ensure robust error handling, especially in the Redis subscription callback.


Verification of Error Handling in Job Event Listeners

The search results indicate that there are various instances of event subscription and handling across the codebase. However, the specific context of error handling within the subscribe method in jobs.controller.ts is not clearly evident from the results.

To ensure robust error handling in the Redis subscription callback, we need to verify if there are any try-catch blocks or error handling mechanisms within the subscribe method or its callback.

Let's refine our search to focus on the subscribe method in jobs.controller.ts and check for any error handling patterns.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check for error handling patterns in job event handling across the project.

# Test: Search for job event handling and error handling.
rg --type typescript $'subscribe' --context 10

Length of output: 80



Script:

#!/bin/bash
# Description: Check for error handling patterns in job event handling across the project.

# Test: Search for job event handling and error handling.
rg --type ts subscribe --context 10

Length of output: 61858



Script:

#!/bin/bash
# Description: Check for error handling within the subscribe method in jobs.controller.ts.

# Test: Search for try-catch blocks or error handling within the subscribe method.
rg --type ts 'subscribe' -A 20 packages/nocodb/src/modules/jobs/jobs.controller.ts | rg 'try|catch|error'

Length of output: 105


Line range hint 167-233: Improve management of closed jobs by ensuring that resources are cleaned up promptly and efficiently.

+ // Ensure that all resources related to closed jobs are cleaned up.
+ this.cleanupClosedJobs(jobId);
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 334e5cf and 528c753.
Files selected for processing (9)
  • packages/nocodb/src/interface/Jobs.ts (1 hunks)
  • packages/nocodb/src/models/Source.ts (4 hunks)
  • packages/nocodb/src/modules/jobs/fallback/jobs.service.ts (1 hunks)
  • packages/nocodb/src/modules/jobs/jobs.controller.ts (11 hunks)
  • packages/nocodb/src/modules/jobs/jobs.module.ts (2 hunks)
  • packages/nocodb/src/modules/jobs/jobs/clean-up/clean-up.processor.ts (1 hunks)
  • packages/nocodb/src/modules/jobs/redis/jobs-redis.ts (1 hunks)
  • packages/nocodb/src/modules/jobs/redis/jobs.service.ts (2 hunks)
  • packages/nocodb/src/utils/common/NcConnectionMgrv2.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/nocodb/src/interface/Jobs.ts
Additional comments not posted (10)
packages/nocodb/src/modules/jobs/fallback/jobs.service.ts (1)

10-10: Verify the purpose of the empty onModuleInit method.

packages/nocodb/src/modules/jobs/redis/jobs.service.ts (2)

105-105: Method for emitting worker commands is implemented correctly.


109-109: Method for emitting primary commands is implemented correctly.

packages/nocodb/src/modules/jobs/redis/jobs-redis.ts (5)

24-57: Verify the initialization logic for Redis clients and ensure that error handling is robust, especially in subscription callbacks.


79-101: Method for subscribing to Redis channels is implemented correctly.


107-120: Method for unsubscribing from Redis channels is implemented correctly.


146-149: Method for emitting worker commands is implemented correctly.


151-154: Method for emitting primary commands is implemented correctly.

packages/nocodb/src/modules/jobs/jobs.controller.ts (2)

167-171: Method for sending job status updates is implemented correctly.


Line range hint 239-290: Method for sending job log updates is implemented correctly.

@dstala dstala added the 🛑 Status: Do Not Merge Used in PR only. The PR cannot be merged due to some reasons. label May 17, 2024
Copy link
Contributor

github-actions bot commented May 17, 2024

Uffizzi Preview deployment-51888 was deleted.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 528c753 and becca55.
Files selected for processing (1)
  • packages/nocodb/src/utils/common/NcConnectionMgrv2.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/nocodb/src/utils/common/NcConnectionMgrv2.ts

@mertmit mertmit removed the 🛑 Status: Do Not Merge Used in PR only. The PR cannot be merged due to some reasons. label May 23, 2024
@mertmit mertmit merged commit 6a334f7 into develop May 23, 2024
24 checks passed
@mertmit mertmit deleted the nc-feat/cleanup branch May 23, 2024 11:53
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.

None yet

3 participants