Skip to content

Add periodic connection re-sync #260

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

Merged
merged 2 commits into from
Apr 4, 2025
Merged

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Apr 3, 2025

This PR adds the resyncConnectionIntervalMs to control how often a given connection should be re-synced.

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration setting, resyncConnectionIntervalMs, which specifies the frequency at which connections should be re-synced, defaulting to 24 hours. This enhancement allows for more efficient management of connection synchronization.
  • Documentation

    • Updated documentation to include details about the new resyncConnectionIntervalMs property in the JSON schema and other relevant sections.

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

The changes refine the connection synchronization logic by updating the query in the registerPollingCallback method to include connections that either require immediate syncing or need to be re-synced after a configurable period. A new setting, resyncConnectionIntervalMs, with a default value corresponding to 24 hours is introduced and propagated through backend constants and various schema/type definitions.

Changes

File(s) Change Summary
packages/backend/src/connectionManager.ts Updated the registerPollingCallback method to include an additional condition for re-syncing connections based on the elapsed time since the last sync.
packages/backend/src/constants.ts Added a new property resyncConnectionIntervalMs set to 1000 * 60 * 60 * 24 (24 hours in milliseconds) to the DEFAULT_SETTINGS.
packages/schemas/.../index.schema.ts, index.type.ts, and schemas/v3/index.json Introduced the resyncConnectionIntervalMs property in the Settings definitions with a number type, a description indicating its purpose for re-sync intervals, and a minimum value constraint of 1.
CHANGELOG.md Added a new configuration setting resyncConnectionIntervalMs under the "Added" section.
docs/self-hosting/more/declarative-config.mdx Added resyncConnectionIntervalMs property in the JSON schema under the Settings definition.

Sequence Diagram(s)

sequenceDiagram
    participant T as Timer
    participant CM as ConnectionManager
    participant DB as Database
    participant Sync as Sync Process

    T->>CM: Trigger registerPollingCallback
    CM->>CM: Compute thresholdDate using resyncConnectionIntervalMs
    CM->>DB: Query connections (SYNC_NEEDED OR (SYNCED/ WARNINGS + outdated))
    DB-->>CM: Return matching connections
    CM->>Sync: Initiate sync process for each connection
Loading

Poem

I'm a coding rabbit in a digital glen,
Hopping through connections time and again.
With a 24-hour tick in my sync routine,
I check each link, crisp and keen.
Celebrating updates with a joyful spring!


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.

❤️ 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@brendan-kellam brendan-kellam changed the title Add period connection re-sync Add periodic connection re-sync Apr 3, 2025
@brendan-kellam brendan-kellam requested a review from msukkari April 3, 2025 23:33
Copy link

@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

🧹 Nitpick comments (2)
packages/backend/src/connectionManager.ts (2)

74-74: Consider handling extreme or invalid interval values.
While the schema enforces a minimum value of 1 for resyncConnectionIntervalMs, it may be safer to validate and clamp values in code to prevent unexpected behavior if the setting is ever overridden or corrupted.


82-95: Consider indexing and test coverage.
The multi-OR query on syncStatus and syncedAt could benefit from indexing in the database for better performance on large datasets. Also ensure that you have an integration test verifying that connections older than the threshold indeed get re-synced.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbd8b22 and 6ecaa86.

📒 Files selected for processing (5)
  • packages/backend/src/connectionManager.ts (1 hunks)
  • packages/backend/src/constants.ts (1 hunks)
  • packages/schemas/src/v3/index.schema.ts (1 hunks)
  • packages/schemas/src/v3/index.type.ts (1 hunks)
  • schemas/v3/index.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (5)
packages/backend/src/constants.ts (1)

10-10: LGTM: New connection re-sync interval setting added.

The addition of resyncConnectionIntervalMs with a default value of 24 hours (in milliseconds) aligns with the PR objective to configure how frequently a connection should be re-synced.

packages/schemas/src/v3/index.schema.ts (1)

26-30: Schema definition for re-sync interval looks good.

The schema properly defines the new resyncConnectionIntervalMs property with appropriate type, description, and minimum value constraint. This matches the implementation in the constants file.

packages/schemas/src/v3/index.type.ts (1)

42-45: TypeScript interface update is correct.

The TypeScript interface has been properly extended with the new optional property, including appropriate JSDoc comment that clearly describes its purpose.

schemas/v3/index.json (1)

26-30: JSON schema definition is consistent.

The JSON schema definition for resyncConnectionIntervalMs is consistent with the TypeScript definitions, having the same type, description, and minimum value constraint.

packages/backend/src/connectionManager.ts (1)

77-81: Verify conflicting or duplicate statuses.
If a connection is already in IN_SYNC_QUEUE or SYNCING, this condition could redundantly place it back into the queue. Confirm that this doesn’t create duplicate or conflicting sync jobs.

Copy link

@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

🧹 Nitpick comments (1)
docs/self-hosting/more/declarative-config.mdx (1)

58-62: Addition of JSON Schema Property: resyncConnectionIntervalMs

The new property is correctly incorporated into the Settings definition. Its type, description, and minimum value are consistent with similar schema properties. As a suggestion, if your configuration loader supports in-schema defaults, consider adding an explicit default (e.g. "default": 86400000") to mirror the backend default of 24 hours.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ecaa86 and 731af2d.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • docs/self-hosting/more/declarative-config.mdx (1 hunks)
🧰 Additional context used
🪛 LanguageTool
CHANGELOG.md

[duplication] ~14-~14: Possible typo: you repeated a word.
Context: .../pull/259)) ### Added - Added config setting `resyncConnectionInterva...

(ENGLISH_WORD_REPEAT_RULE)

🔇 Additional comments (1)
CHANGELOG.md (1)

14-16: Changelog Entry for resyncConnectionIntervalMs is Well-Formulated

The new changelog entry clearly documents the addition of the resyncConnectionIntervalMs setting along with its purpose and a link to PR [#260]. This helps maintain clarity in project history.

🧰 Tools
🪛 LanguageTool

[duplication] ~14-~14: Possible typo: you repeated a word.
Context: .../pull/259)) ### Added - Added config setting `resyncConnectionInterva...

(ENGLISH_WORD_REPEAT_RULE)

@brendan-kellam brendan-kellam merged commit 21bbe09 into main Apr 4, 2025
5 checks passed
@brendan-kellam brendan-kellam deleted the bkellam/period_resync branch April 4, 2025 00:51
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