refactor(core): Make orchestration service smaller (#11275)

This commit is contained in:
Iván Ovejero
2024-10-16 17:34:32 +02:00
committed by GitHub
parent bf28fbefe5
commit d37acdb873
19 changed files with 158 additions and 157 deletions

View File

@@ -48,6 +48,7 @@ import { WorkflowExecutionService } from '@/workflows/workflow-execution.service
import { WorkflowStaticDataService } from '@/workflows/workflow-static-data.service';
import { ExecutionService } from './executions/execution.service';
import { Publisher } from './scaling/pubsub/publisher.service';
interface QueuedActivation {
activationMode: WorkflowActivateMode;
@@ -75,6 +76,7 @@ export class ActiveWorkflowManager {
private readonly activeWorkflowsService: ActiveWorkflowsService,
private readonly workflowExecutionService: WorkflowExecutionService,
private readonly instanceSettings: InstanceSettings,
private readonly publisher: Publisher,
) {}
async init() {
@@ -517,8 +519,9 @@ export class ActiveWorkflowManager {
{ shouldPublish } = { shouldPublish: true },
) {
if (this.orchestrationService.isMultiMainSetupEnabled && shouldPublish) {
await this.orchestrationService.publish('add-webhooks-triggers-and-pollers', {
workflowId,
void this.publisher.publishCommand({
command: 'add-webhooks-triggers-and-pollers',
payload: { workflowId },
});
return;
@@ -526,8 +529,8 @@ export class ActiveWorkflowManager {
let workflow: Workflow;
const shouldAddWebhooks = this.orchestrationService.shouldAddWebhooks(activationMode);
const shouldAddTriggersAndPollers = this.orchestrationService.shouldAddTriggersAndPollers();
const shouldAddWebhooks = this.shouldAddWebhooks(activationMode);
const shouldAddTriggersAndPollers = this.shouldAddTriggersAndPollers();
const shouldDisplayActivationMessage =
(shouldAddWebhooks || shouldAddTriggersAndPollers) &&
@@ -717,7 +720,10 @@ export class ActiveWorkflowManager {
);
}
await this.orchestrationService.publish('remove-triggers-and-pollers', { workflowId });
void this.publisher.publishCommand({
command: 'remove-triggers-and-pollers',
payload: { workflowId },
});
return;
}
@@ -810,4 +816,29 @@ export class ActiveWorkflowManager {
async removeActivationError(workflowId: string) {
await this.activationErrorsService.deregister(workflowId);
}
/**
* Whether this instance may add webhooks to the `webhook_entity` table.
*/
shouldAddWebhooks(activationMode: WorkflowActivateMode) {
// Always try to populate the webhook entity table as well as register the webhooks
// to prevent issues with users upgrading from a version < 1.15, where the webhook entity
// was cleared on shutdown to anything past 1.28.0, where we stopped populating it on init,
// causing all webhooks to break
if (activationMode === 'init') return true;
if (activationMode === 'leadershipChange') return false;
return this.instanceSettings.isLeader; // 'update' or 'activate'
}
/**
* Whether this instance may add triggers and pollers to memory.
*
* In both single- and multi-main setup, only the leader is allowed to manage
* triggers and pollers in memory, to ensure they are not duplicated.
*/
shouldAddTriggersAndPollers() {
return this.instanceSettings.isLeader;
}
}