Skip to content

The open alternative to Salesforce, designed for AI.

fix(upgrade): invalidate upgrade-status cache on command end (#21497)

Charles Bochet577b22df46a1
diff --git a/packages/twenty-server/src/database/commands/run-instance-commands.command.ts b/packages/twenty-server/src/database/commands/run-instance-commands.command.ts
index 0db1dca6541..1a5a44b2659 100644
--- a/packages/twenty-server/src/database/commands/run-instance-commands.command.ts
+++ b/packages/twenty-server/src/database/commands/run-instance-commands.command.ts
@@ -10,6 +10,7 @@ import { InstanceCommandRunnerService } from 'src/engine/core-modules/upgrade/se
import { UpgradeCommandRegistryService } from 'src/engine/core-modules/upgrade/services/upgrade-command-registry.service';
import { UpgradeMigrationService } from 'src/engine/core-modules/upgrade/services/upgrade-migration.service';
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
+import { UpgradeStatusService } from 'src/engine/core-modules/upgrade/services/upgrade-status.service';
import { WorkspaceVersionService } from 'src/engine/workspace-manager/workspace-version/services/workspace-version.service';
type RunInstanceCommandsOptions = {
@@ -34,6 +35,7 @@ export class RunInstanceCommandsCommand extends CommandRunner {
private readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,
private readonly instanceUpgradeService: InstanceCommandRunnerService,
private readonly upgradeMigrationService: UpgradeMigrationService,
+ private readonly upgradeStatusService: UpgradeStatusService,
) {
super();
}
@@ -102,6 +104,20 @@ export class RunInstanceCommandsCommand extends CommandRunner {
chalk.red(`Instance commands failed: ${error.message}`),
);
throw error;
+ } finally {
+ await this.safeInvalidateUpgradeStatusCache();
+ }
+ }
+
+ private async safeInvalidateUpgradeStatusCache(): Promise<void> {
+ try {
+ await this.upgradeStatusService.invalidateInstanceAndAllWorkspacesStatus();
+ } catch (error) {
+ this.logger.warn(
+ `Failed to invalidate upgrade-status cache: ${
+ error instanceof Error ? error.message : String(error)
+ }`,
+ );
}
}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts
index 81ecc588204..3afcd97cecf 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/upgrade.command.ts
@@ -4,6 +4,7 @@ import { isDefined } from 'twenty-shared/utils';
import { CommandLogger } from 'src/database/commands/logger';
import { UpgradeSequenceReaderService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-reader.service';
import { UpgradeSequenceRunnerService } from 'src/engine/core-modules/upgrade/services/upgrade-sequence-runner.service';
+import { UpgradeStatusService } from 'src/engine/core-modules/upgrade/services/upgrade-status.service';
import { formatUpgradeLog } from 'src/engine/core-modules/upgrade/utils/format-upgrade-log.util';
type RawUpgradeCommandOptions = {
@@ -32,6 +33,7 @@ export class UpgradeCommand extends CommandRunner {
constructor(
protected readonly upgradeSequenceReaderService: UpgradeSequenceReaderService,
protected readonly upgradeSequenceRunnerService: UpgradeSequenceRunnerService,
+ protected readonly upgradeStatusService: UpgradeStatusService,
) {
super();
this.logger = new CommandLogger({
@@ -190,6 +192,23 @@ export class UpgradeCommand extends CommandRunner {
}),
);
throw error;
+ } finally {
+ await this.safeInvalidateUpgradeStatusCache();
+ }
+ }
+
+ private async safeInvalidateUpgradeStatusCache(): Promise<void> {
+ try {
+ await this.upgradeStatusService.invalidateInstanceAndAllWorkspacesStatus();
+ } catch (error) {
+ this.logger.error(
+ formatUpgradeLog({
+ humanMessage: `Failed to invalidate upgrade-status cache: ${
+ error instanceof Error ? error.message : String(error)
+ }`,
+ event: 'cache.invalidate.failed',
+ }),
+ );
}
}
}