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

add cluster matching sync timestamp and logs #1913

Merged
merged 2 commits into from
Jan 22, 2025

Conversation

CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Jan 22, 2025

relate: Giveth/giveth-dapps-v2#4274 (comment)

Summary by CodeRabbit

Release Notes

  • New Features
    • Added a timestamp tracking feature for cluster matching synchronization.
  • Database Changes
    • Introduced clusterMatchingSyncAt column in QF Round table to record sync timing.
  • Improvements
    • Enhanced logging for cluster matching worker to improve traceability.
    • Added better error handling in synchronization processes.
    • Updated active QF Round with the last synchronization timestamp after job execution.

Copy link
Collaborator

@kkatusic kkatusic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ;) thx @CarlosQ96

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a new timestamp column clusterMatchingSyncAt to track the synchronization timing for cluster matching in the qf_round table. The changes span across a migration file, an entity definition, and worker/service files. A new database migration is created to add the column, the QfRound entity is updated to include the new field, and the synchronization job is modified to update the timestamp when cluster matching is performed.

Changes

File Change Summary
migration/1737544105947-addClusterMatchingSyncAtTimestamp.ts Added migration to create clusterMatchingSyncAt column in qf_round table
src/entities/qfRound.ts Added clusterMatchingSyncAt: Date field to QfRound class
src/services/cronJobs/syncEstimatedClusterMatchingJob.ts Updated to set clusterMatchingSyncAt timestamp after successful sync
src/workers/cocm/estimatedClusterMatchingWorker.ts Enhanced logging for fetchEstimatedClusterMatching and updateEstimatedClusterMatching methods

Possibly related PRs

  • Feature cluster matching #1862: The main PR introduces a new column clusterMatchingSyncAt in the qf_round table, while the retrieved PR adds a new table estimated_cluster_matching and modifies related entities, indicating a connection in the context of cluster matching functionality.

Suggested reviewers

  • kkatusic

Poem

🐰 Sync's whisper, a timestamp's tale
Clusters dancing, without fail
Migration's magic, column bright
Tracking progress with pure delight
Code hops forward, rabbit's glee! 🕒


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1d6c94 and 33e389f.

📒 Files selected for processing (1)
  • src/entities/qfRound.ts (1 hunks)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 comments (1)
src/services/cronJobs/syncEstimatedClusterMatchingJob.ts (1)

Line range hint 63-71: Remove duplicate Thread.terminate() call.

The worker thread is being terminated twice - once in the finally block and once after it. This could lead to attempting to terminate an already terminated thread.

Remove the duplicate termination:

  } catch (e) {
    logger.error('fetchAndUpdateClusterEstimatedMatching error', e);
  } finally {
    await Thread.terminate(matchingWorker);
  }
-
-  await Thread.terminate(matchingWorker);
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9bcaded and c1d6c94.

📒 Files selected for processing (4)
  • migration/1737544105947-addClusterMatchingSyncAtTimestamp.ts (1 hunks)
  • src/entities/qfRound.ts (1 hunks)
  • src/services/cronJobs/syncEstimatedClusterMatchingJob.ts (1 hunks)
  • src/workers/cocm/estimatedClusterMatchingWorker.ts (1 hunks)
🔇 Additional comments (3)
migration/1737544105947-addClusterMatchingSyncAtTimestamp.ts (1)

1-25: LGTM! Well-structured migration with proper safety checks.

The migration follows TypeORM best practices with proper up/down methods and includes a safety check before adding the column.

src/services/cronJobs/syncEstimatedClusterMatchingJob.ts (1)

59-62: LGTM! Timestamp update is properly placed after successful sync.

The timestamp update is correctly placed after the successful completion of the sync operation.

src/workers/cocm/estimatedClusterMatchingWorker.ts (1)

30-30: LGTM! Debug log added for operation tracking.

The debug log for operation start is appropriately placed.

Comment on lines +17 to +26
logger.debug('fetchEstimatedClusterMatching() has been called');
const matchingData =
await getClusterMatchingAdapter().fetchEstimatedClusterMatchings(
matchingDataInput,
);
logger.debug(
'fetchEstimatedClusterMatching() has worked with params',
String(matchingData),
);
return matchingData;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve logging security for matchingData.

Converting matchingData directly to string could expose sensitive information in logs. Consider logging only necessary metadata.

Suggested improvement:

-    logger.debug(
-      'fetchEstimatedClusterMatching() has worked with params',
-      String(matchingData),
-    );
+    logger.debug(
+      'fetchEstimatedClusterMatching() completed',
+      {
+        recordCount: matchingData?.length || 0,
+        timestamp: new Date().toISOString()
+      }
+    );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.debug('fetchEstimatedClusterMatching() has been called');
const matchingData =
await getClusterMatchingAdapter().fetchEstimatedClusterMatchings(
matchingDataInput,
);
logger.debug(
'fetchEstimatedClusterMatching() has worked with params',
String(matchingData),
);
return matchingData;
logger.debug('fetchEstimatedClusterMatching() has been called');
const matchingData =
await getClusterMatchingAdapter().fetchEstimatedClusterMatchings(
matchingDataInput,
);
logger.debug(
'fetchEstimatedClusterMatching() completed',
{
recordCount: matchingData?.length || 0,
timestamp: new Date().toISOString()
}
);
return matchingData;

Comment on lines 129 to 131
@Field(_type => Date)
@Column({ nullable: true })
clusterMatchingSyncAt: Date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Align GraphQL and database column nullability.

The field is nullable in the database but required in GraphQL. This mismatch could cause runtime errors when the field is null.

Update the field definition to match nullability:

-  @Field(_type => Date)
+  @Field(_type => Date, { nullable: true })
   @Column({ nullable: true })
   clusterMatchingSyncAt: Date;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Field(_type => Date)
@Column({ nullable: true })
clusterMatchingSyncAt: Date;
@Field(_type => Date, { nullable: true })
@Column({ nullable: true })
clusterMatchingSyncAt: Date;

@CarlosQ96 CarlosQ96 merged commit 7e9c1b6 into staging Jan 22, 2025
1 check failed
@CarlosQ96 CarlosQ96 deleted the feature_add_sync_timestamp_qf branch January 22, 2025 11:59
CarlosQ96 added a commit that referenced this pull request Jan 27, 2025
* throw error on un-vouching the givbackseligible projects

* update message

* optimize the approveMultipleProjects

* make projects verified if they become givbacksEligible

* prevent approve or reject draft projects

* fix records

* fix conditions

* use redirectUrl

* fix tests

* add unverifyProjectsTestCases

* add test:projectVerificationTab

* temporary comment

* fix typo

* send email when project verification status changed

* Feat/Generating public user data

* added tests for querying user basic data

* add includeUnlisted to FilterProjectQueryInputParams

* return proper projects

* add recipient address to streams when nonexistent (#1890)

* started endaoment update feature

* Superfluid Base Support (#1893)

* finish project endpoint for superfluid to read

* add filters for network and tokens for recurringdonations

* fix verification logic and emails for base network streams

* Update src/resolvers/recurringDonationResolver.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* comment network test and add cbBTC to seeds

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* remove project validation from anchor contract

* Add networkId logic to superfluid subgraphs (#1896)

* add networkId logic to superfluid subgraphs

* remove networkId from api call to superfluid

* fix eslint

* fix linkedin scope

* fix user info link to user info

* cron job for sitemap generating

* adding additional projects to Endaoment list

* started cronjob

* finished cron job

* Feature cluster matching (#1862)

* add cluster matching entity

* add cluster matching adapters

* finish cocm adapter

* improve error handling for cluster matching

* comment broken contract tests by missing eth_getCode Method

* add feedback to handle qf cases

* add cluster matching job to bootstrap file

* fix coderabbit feedback PR

* termine worker if an exception is raised

* fix updateUser condition to handle email undefined case

* fixed one variable; added cronjob env suggested by Carlos

* removed redundant code

* check config value

* fix calling env variable

* fix/removing endaomentId from update

* add qfStrategy to qfRounds (#1903)

* update bootstrap.js adding check endaoment

* adding sitemap cronjob to bootstrap

* additional logger data

* fine tuninnig log

* improve logger

* fixing endaoment id

* Set default zero for power balance snapshot on no return from balance aggregator (#1732)

Ref #1655

* Fix/Sitemap env variables

* fix missing prefix for url

* fix matching cap calculation

* fix data insertion for cluster matching

* add user passport score null case to clustermatching queries

* fix error handling in cocm adapter

* add cluster matching sync timestamp and logs (#1913)

* add cluster matching sync timestamp and logs

* add nullability to clustermathicng syncAT

* fix db call in worker for cluster matching

* add uniquness constraint to estimatedclustedMatching

* handle undefined case for instant power boosting services

* better error handling in worker job

* fixing prettier problem

* Disable cluster matching

---------

Co-authored-by: Cherik <[email protected]>
Co-authored-by: kkatusic <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Mitch <[email protected]>
Co-authored-by: Lovel George <[email protected]>
Co-authored-by: Amin Latifi <[email protected]>
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