UNPKG

n8n

Version:

n8n Workflow Automation Tool

63 lines 3.27 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var AgentInterruptedExecutionSweeper_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.AgentInterruptedExecutionSweeper = void 0; const backend_common_1 = require("@n8n/backend-common"); const di_1 = require("@n8n/di"); const agent_execution_service_1 = require("./agent-execution.service"); const agent_execution_repository_1 = require("./repositories/agent-execution.repository"); let AgentInterruptedExecutionSweeper = AgentInterruptedExecutionSweeper_1 = class AgentInterruptedExecutionSweeper { constructor(logger, executionRepository, executionService) { this.logger = logger; this.executionRepository = executionRepository; this.executionService = executionService; this.logger = this.logger.scoped('agents'); } async sweep() { let running; try { running = await this.executionRepository.findRunning(); } catch (error) { this.logger.error('Failed to query running agent executions', { error }); return; } for (const execution of running) { try { if (execution.updatedAt.getTime() > Date.now() - AgentInterruptedExecutionSweeper_1.LIVENESS_GRACE_MS) { continue; } if (await this.executionService.finalizeInterruptedExecution(execution)) { this.logger.info('Marked abandoned agent execution as interrupted', { executionId: execution.id, threadId: execution.threadId, }); } } catch (error) { this.logger.error('Failed to finalize interrupted agent execution', { executionId: execution.id, threadId: execution.threadId, error, }); } } } }; exports.AgentInterruptedExecutionSweeper = AgentInterruptedExecutionSweeper; AgentInterruptedExecutionSweeper.LIVENESS_GRACE_MS = 2 * 60 * 1000; exports.AgentInterruptedExecutionSweeper = AgentInterruptedExecutionSweeper = AgentInterruptedExecutionSweeper_1 = __decorate([ (0, di_1.Service)(), __metadata("design:paramtypes", [backend_common_1.Logger, agent_execution_repository_1.AgentExecutionRepository, agent_execution_service_1.AgentExecutionService]) ], AgentInterruptedExecutionSweeper); //# sourceMappingURL=agent-interrupted-execution-sweeper.js.map