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

refactor(core): Streamline flows in multi-main mode (no-changelog) #8446

Merged
merged 33 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e587d25
Abstract away activations
ivov Jan 25, 2024
30040cf
Make inter-main comms unidirectional
ivov Jan 25, 2024
761b397
Add tests for new methods
ivov Jan 25, 2024
5799727
Remove from `ActiveWorkflowRunner` tests
ivov Jan 25, 2024
d6b496a
Update tests
ivov Jan 25, 2024
13f4a63
Add `Reporter.info`
ivov Jan 25, 2024
8131d51
Fix webhooks tests
ivov Jan 25, 2024
de0bd75
Move logs
ivov Jan 25, 2024
4108e3a
Add note
ivov Jan 25, 2024
515adc1
Tighten condition
ivov Jan 25, 2024
af2e114
Tweak follower behavior
ivov Jan 25, 2024
fef6606
Prevent follower removal
ivov Jan 25, 2024
9717692
Cleaner syntax
ivov Jan 25, 2024
e7ece92
Better docline
ivov Jan 25, 2024
1ea1be0
Better title
ivov Jan 25, 2024
b6d7e9a
Tweaks
ivov Jan 26, 2024
64fcae7
Remove superfluous comments
ivov Jan 26, 2024
a20cf09
Tighten wording
ivov Jan 26, 2024
59c9776
Fix test
ivov Jan 26, 2024
8fcca43
refactor(core): Bifurcate handling of webhooks vs. triggers and polle…
ivov Jan 31, 2024
e03829a
Merge master, fix conflicts
ivov Jan 31, 2024
1a35296
Fix tests
ivov Jan 31, 2024
aa8a3d0
Merge branch 'master' into simplify-flows-in-multi-main-mode
ivov Jan 31, 2024
0cfc9f0
Mark cleanup items
ivov Feb 1, 2024
341f9b3
Ensure handler main informs FE of activation failure
ivov Feb 1, 2024
3c37353
Prevent publishing on `init` and `leadershipChange`
ivov Feb 2, 2024
9207965
Switch logs back to debug
ivov Feb 2, 2024
63016b1
Another log switch
ivov Feb 2, 2024
b46b6b1
Reduce diff
ivov Feb 2, 2024
6d88a50
Preserve original logging behavior
ivov Feb 2, 2024
a316429
Improve var name
ivov Feb 2, 2024
f3f7ad0
Ensure activation and deactivation are pushed to leader's and followe…
ivov Feb 2, 2024
af99cd6
Fix typo
ivov Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ export async function handleCommandMessageMain(messageString: string) {
return message;
}

if (Container.get(OrchestrationService).isFollower) break;
const orchestrationService = Container.get(OrchestrationService);

if (orchestrationService.isFollower) break;

if (typeof message.payload?.workflowId !== 'string') break;

Expand All @@ -95,6 +97,9 @@ export async function handleCommandMessageMain(messageString: string) {
});

push.broadcast('workflowActivated', { workflowId });

// instruct followers to show deactivation in UI
await orchestrationService.publish('display-workflow-activation', { workflowId });
} catch (error) {
if (error instanceof Error) {
await Container.get(WorkflowRepository).update(workflowId, { active: false });
Expand All @@ -120,7 +125,9 @@ export async function handleCommandMessageMain(messageString: string) {
return message;
}

if (Container.get(OrchestrationService).isFollower) break;
const orchestrationService = Container.get(OrchestrationService);

if (orchestrationService.isFollower) break;

if (typeof message.payload?.workflowId !== 'string') break;

Expand All @@ -131,6 +138,41 @@ export async function handleCommandMessageMain(messageString: string) {
await activeWorkflowRunner.removeActivationError(workflowId);
await activeWorkflowRunner.removeWorkflowTriggersAndPollers(workflowId);

push.broadcast('workflowDeactivated', { workflowId });

// instruct followers to show workflow deactivation in UI
await orchestrationService.publish('display-workflow-deactivation', { workflowId });

break;
}

case 'display-workflow-activation': {
if (!debounceMessageReceiver(message, 100)) {
message.payload = { result: 'debounced' };
return message;
}

const { workflowId } = message.payload ?? {};

if (typeof workflowId !== 'string') break;

push.broadcast('workflowActivated', { workflowId });
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be sure, the UI is ready to only display this if the currently open workflow ID matches to the one sent in the payload right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The FE at pushConnection.ts receives this workflow ID and calls store methods:

if (receivedData.type === 'workflowActivated') {
	this.workflowsStore.setWorkflowActive(receivedData.data.workflowId);
	return true;
}

if (receivedData.type === 'workflowDeactivated') {
	this.workflowsStore.setWorkflowInactive(receivedData.data.workflowId);
	return true;
}

And the store methods compare the pushed workflow ID against this.workflow.id, which as far as I understand is the workflow on canvas.

setWorkflowActive(workflowId: string): void {
	const uiStore = useUIStore();
	uiStore.stateIsDirty = false;
	const index = this.activeWorkflows.indexOf(workflowId);
	if (index === -1) {
		this.activeWorkflows.push(workflowId);
	}
	if (this.workflowsById[workflowId]) {
		this.workflowsById[workflowId].active = true;
	}
	if (workflowId === this.workflow.id) {
		this.setActive(true);
	}
},

setWorkflowInactive(workflowId: string): void {
	const index = this.activeWorkflows.indexOf(workflowId);
	if (index !== -1) {
		this.activeWorkflows.splice(index, 1);
	}
	if (this.workflowsById[workflowId]) {
		this.workflowsById[workflowId].active = false;
	}
	if (workflowId === this.workflow.id) {
		this.setActive(false);
	}
},


break;
}

case 'display-workflow-deactivation': {
if (!debounceMessageReceiver(message, 100)) {
message.payload = { result: 'debounced' };
return message;
}

const { workflowId } = message.payload ?? {};

if (typeof workflowId !== 'string') break;

push.broadcast('workflowDeactivated', { workflowId });

break;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/services/redis/RedisServiceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type RedisServiceCommand =
| 'stopWorker'
| 'reloadLicense'
| 'reloadExternalSecretsProviders'
| 'display-workflow-activation' // multi-main only
| 'display-workflow-deactivation' // multi-main only
| 'add-webhooks-triggers-and-pollers' // multi-main only
| 'remove-triggers-and-pollers' // multi-main only
| 'workflow-failed-to-activate' // multi-main only
Expand Down
Loading