2023-12-12 06:18:32 -08:00
|
|
|
import { Get, RestController } from '@/decorators';
|
|
|
|
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
|
|
|
import { MultiMainSetup } from '@/services/orchestration/main/MultiMainSetup.ee';
|
|
|
|
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
|
|
|
import { In } from 'typeorm';
|
2023-12-27 07:55:01 -08:00
|
|
|
import { WebhookEntity } from '@/databases/entities/WebhookEntity';
|
2023-12-12 06:18:32 -08:00
|
|
|
|
|
|
|
@RestController('/debug')
|
|
|
|
export class DebugController {
|
|
|
|
constructor(
|
|
|
|
private readonly multiMainSetup: MultiMainSetup,
|
|
|
|
private readonly activeWorkflowRunner: ActiveWorkflowRunner,
|
|
|
|
private readonly workflowRepository: WorkflowRepository,
|
|
|
|
) {}
|
|
|
|
|
|
|
|
@Get('/multi-main-setup')
|
|
|
|
async getMultiMainSetupDetails() {
|
|
|
|
const leaderKey = await this.multiMainSetup.fetchLeaderKey();
|
|
|
|
|
2023-12-27 07:55:01 -08:00
|
|
|
const triggersAndPollers = await this.workflowRepository.find({
|
2023-12-12 06:18:32 -08:00
|
|
|
select: ['id', 'name'],
|
|
|
|
where: { id: In(this.activeWorkflowRunner.allActiveInMemory()) },
|
|
|
|
});
|
|
|
|
|
2023-12-27 07:55:01 -08:00
|
|
|
const webhooks = (await this.workflowRepository
|
|
|
|
.createQueryBuilder('workflow')
|
|
|
|
.select('DISTINCT workflow.id, workflow.name')
|
|
|
|
.innerJoin(WebhookEntity, 'webhook_entity', 'workflow.id = webhook_entity.workflowId')
|
|
|
|
.execute()) as Array<{ id: string; name: string }>;
|
|
|
|
|
2023-12-12 06:18:32 -08:00
|
|
|
const activationErrors = await this.activeWorkflowRunner.getAllWorkflowActivationErrors();
|
|
|
|
|
|
|
|
return {
|
|
|
|
instanceId: this.multiMainSetup.instanceId,
|
|
|
|
leaderKey,
|
2023-12-27 07:55:01 -08:00
|
|
|
isLeader: this.multiMainSetup.isLeader,
|
|
|
|
activeWorkflows: {
|
|
|
|
webhooks, // webhook-based active workflows
|
|
|
|
triggersAndPollers, // poller- and trigger-based active workflows
|
|
|
|
},
|
2023-12-12 06:18:32 -08:00
|
|
|
activationErrors,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|