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

@@ -12,6 +12,7 @@ import config from '@/config';
import type { User } from '@/databases/entities/user';
import { OnShutdown } from '@/decorators/on-shutdown';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { Publisher } from '@/scaling/pubsub/publisher.service';
import { OrchestrationService } from '@/services/orchestration.service';
import { TypedEmitter } from '@/typed-emitter';
@@ -39,7 +40,10 @@ export class Push extends TypedEmitter<PushEvents> {
private backend = useWebSockets ? Container.get(WebSocketPush) : Container.get(SSEPush);
constructor(private readonly orchestrationService: OrchestrationService) {
constructor(
private readonly orchestrationService: OrchestrationService,
private readonly publisher: Publisher,
) {
super();
if (useWebSockets) this.backend.on('message', (msg) => this.emit('message', msg));
@@ -89,8 +93,10 @@ export class Push extends TypedEmitter<PushEvents> {
* relay the former's execution lifecycle events to the creator's frontend.
*/
if (this.orchestrationService.isMultiMainSetupEnabled && !this.backend.hasPushRef(pushRef)) {
const payload = { type, args: data, pushRef };
void this.orchestrationService.publish('relay-execution-lifecycle-event', payload);
void this.publisher.publishCommand({
command: 'relay-execution-lifecycle-event',
payload: { type, args: data, pushRef },
});
return;
}