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 option to synchronize all active workspaces at once #6221

Merged
merged 6 commits into from
Jul 11, 2024

Conversation

ijreilly
Copy link
Collaborator

In the longer term, we want to improve the efficiency and reliability of the sync-metadata command, by choosing an error handling strategy and paying greater attention to health checks.
In the meantime, this PR adds an option to run the sync-metadata command on all active workspaces at once.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Added --sync-all-active-workspaces option in /packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command.ts
  • Introduced isWorkspaceActive utility in /packages/twenty-server/src/database/commands/utils/is-workspace-active.utils.ts
  • Refactored workspace activity check in /packages/twenty-server/src/database/commands/0-22-add-new-address-field-to-views-with-deprecated-address.command.ts
  • Updated module imports in /packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module.ts to support new feature

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Enhanced sync-workspace-metadata.command.ts to support synchronizing all active workspaces.
  • Improved error handling and logging for bulk workspace synchronization.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@@ -81,7 +76,11 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
const activeWorkspaceIds = (
await Promise.all(
workspaces.map(async (workspace) => {
const isActive = await this.workspaceIsActive(workspace);
const isActive = await isWorkspaceActive({
Copy link
Member

Choose a reason for hiding this comment

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

move to workspace.service.ts

const workspaceIds = options.workspaceId ? [options.workspaceId] : [];
let workspaceIds = options.workspaceId ? [options.workspaceId] : [];

if (options.syncAllActiveWorkspaces && isEmpty(workspaceIds)) {
Copy link
Member

Choose a reason for hiding this comment

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

no need for onlyActiveWorkspaces

const activeWorkspaceIds = (
await Promise.all(
workspaces.map(async (workspace) => {
const isActive = await isWorkspaceActive({
Copy link
Member

Choose a reason for hiding this comment

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

add areWorkspaceActive query

);
}
} catch (error) {
if (options.syncAllActiveWorkspaces) {
Copy link
Member

Choose a reason for hiding this comment

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

if (options.throwOnFirstFail)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added getActiveWorkspaceIds method in workspace.service.ts to fetch active workspace IDs
  • Updated sync-workspace-metadata.command.ts to synchronize all active workspaces
  • Replaced direct repository access with WorkspaceService in 0-22-add-new-address-field-to-views-with-deprecated-address.command.ts
  • Removed is-workspace-active.utils.ts file
  • Updated workspace.service.ts constructor to include BillingSubscription and FeatureFlagEntity repositories

4 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Replaced WorkspaceService with WorkspaceStatusService in packages/twenty-server/src/database/commands/0-22-add-new-address-field-to-views-with-deprecated-address.command.ts
  • Removed getActiveWorkspaceIds method from packages/twenty-server/src/engine/core-modules/workspace/services/workspace.service.ts
  • Added WorkspaceStatusModule to packages/twenty-server/src/engine/workspace-manager/workspace-manager.module.ts
  • Introduced WorkspaceStatusService in packages/twenty-server/src/engine/workspace-manager/workspace-status/services/workspace-status.service.ts
  • Added option to synchronize all active workspaces in packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command.ts

9 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

Comment on lines +28 to +29
const workspaces = await this.workspaceRepository.find();
const workspaceIds = workspaces.map((workspace) => workspace.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

🪶 style: Fetching all workspaces without any filters could be inefficient for large datasets. Consider adding pagination or filtering.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Corrected import path for WorkspaceStatusModule in packages/twenty-server/src/engine/workspace-manager/workspace-manager.module.ts
  • Renamed workspace-manager.module.ts to workspace-status.module.ts in packages/twenty-server/src/engine/workspace-manager/workspace-status/
  • Updated imports to include TypeOrmModule with Workspace, BillingSubscription, and FeatureFlagEntity entities in workspace-status.module.ts
  • Ensured WorkspaceStatusService is provided in workspace-status.module.ts

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@ijreilly ijreilly force-pushed the sync-metadata-active-workspaces branch from a0ad08c to abcf8e6 Compare July 11, 2024 17:38
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Added WorkspaceStatusModule to database-command.module.ts imports
  • Enhanced sync-workspace-metadata.command.ts to sync all active workspaces using WorkspaceStatusService
  • Improved error handling and logging in sync-workspace-metadata.command.ts
  • Added WorkspaceStatusModule and removed unnecessary imports in workspace-sync-metadata-commands.module.ts

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Introduced check for 'IS_BILLING_ENABLED' in workspace-status.service.ts to filter active workspaces by billing status.
  • Added EnvironmentModule to WorkspaceStatusModule imports in workspace-manager.module.ts.
  • Enhanced sync-workspace-metadata.command.ts to sync all active workspaces if no specific ID is provided.
  • Improved logging and error handling in sync-workspace-metadata.command.ts.

3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

LGTM!

@charlesBochet charlesBochet merged commit 5ad287b into main Jul 11, 2024
6 checks passed
@charlesBochet charlesBochet deleted the sync-metadata-active-workspaces branch July 11, 2024 17:48
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