mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
fix(core): Ensure pruning starts only after migrations have completed (#7626)
https://linear.app/n8n/issue/PAY-986/bug-execution-pruning-timer-is-started-before-the-database-is-ready --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
c857e42677
commit
f748de9567
|
@ -41,7 +41,6 @@ import {
|
||||||
WorkflowStatisticsRepository,
|
WorkflowStatisticsRepository,
|
||||||
WorkflowTagMappingRepository,
|
WorkflowTagMappingRepository,
|
||||||
} from '@db/repositories';
|
} from '@db/repositories';
|
||||||
import { PruningService } from '@/services/pruning.service';
|
|
||||||
|
|
||||||
export const collections = {} as IDatabaseCollections;
|
export const collections = {} as IDatabaseCollections;
|
||||||
|
|
||||||
|
@ -192,10 +191,6 @@ export async function init(testConnectionOptions?: ConnectionOptions): Promise<v
|
||||||
collections.Settings = Container.get(SettingsRepository);
|
collections.Settings = Container.get(SettingsRepository);
|
||||||
collections.Credentials = Container.get(CredentialsRepository);
|
collections.Credentials = Container.get(CredentialsRepository);
|
||||||
collections.Workflow = Container.get(WorkflowRepository);
|
collections.Workflow = Container.get(WorkflowRepository);
|
||||||
|
|
||||||
const pruningService = Container.get(PruningService);
|
|
||||||
|
|
||||||
if (await pruningService.isPruningEnabled()) pruningService.startPruning();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function migrate() {
|
export async function migrate() {
|
||||||
|
|
|
@ -65,6 +65,8 @@ export class Start extends BaseCommand {
|
||||||
|
|
||||||
protected server = new Server();
|
protected server = new Server();
|
||||||
|
|
||||||
|
private pruningService: PruningService;
|
||||||
|
|
||||||
constructor(argv: string[], cmdConfig: IConfig) {
|
constructor(argv: string[], cmdConfig: IConfig) {
|
||||||
super(argv, cmdConfig);
|
super(argv, cmdConfig);
|
||||||
this.setInstanceType('main');
|
this.setInstanceType('main');
|
||||||
|
@ -110,9 +112,9 @@ export class Start extends BaseCommand {
|
||||||
// Note: While this saves a new license cert to DB, the previous entitlements are still kept in memory so that the shutdown process can complete
|
// Note: While this saves a new license cert to DB, the previous entitlements are still kept in memory so that the shutdown process can complete
|
||||||
await Container.get(License).shutdown();
|
await Container.get(License).shutdown();
|
||||||
|
|
||||||
const pruningService = Container.get(PruningService);
|
if (await this.pruningService.isPruningEnabled()) {
|
||||||
|
await this.pruningService.stopPruning();
|
||||||
if (await pruningService.isPruningEnabled()) await pruningService.stopPruning();
|
}
|
||||||
|
|
||||||
if (config.getEnv('leaderSelection.enabled')) {
|
if (config.getEnv('leaderSelection.enabled')) {
|
||||||
const { MultiMainInstancePublisher } = await import(
|
const { MultiMainInstancePublisher } = await import(
|
||||||
|
@ -342,6 +344,11 @@ export class Start extends BaseCommand {
|
||||||
|
|
||||||
await this.server.start();
|
await this.server.start();
|
||||||
|
|
||||||
|
this.pruningService = Container.get(PruningService);
|
||||||
|
if (await this.pruningService.isPruningEnabled()) {
|
||||||
|
this.pruningService.startPruning();
|
||||||
|
}
|
||||||
|
|
||||||
// Start to get active workflows and run their triggers
|
// Start to get active workflows and run their triggers
|
||||||
await this.activeWorkflowRunner.init();
|
await this.activeWorkflowRunner.init();
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,9 @@ export class PruningService {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @important Call only after DB connection is established and migrations have completed.
|
||||||
|
*/
|
||||||
startPruning() {
|
startPruning() {
|
||||||
this.setSoftDeletionInterval();
|
this.setSoftDeletionInterval();
|
||||||
this.scheduleHardDeletion();
|
this.scheduleHardDeletion();
|
||||||
|
|
Loading…
Reference in a new issue