UNPKG

n8n

Version:

n8n Workflow Automation Tool

70 lines 3.53 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WorkflowPublishedDataService = void 0; const backend_common_1 = require("@n8n/backend-common"); const db_1 = require("@n8n/db"); const di_1 = require("@n8n/di"); const ensure_error_1 = require("@n8n/utils/errors/ensure-error"); const cache_service_1 = require("../services/cache/cache.service"); const NO_EXPIRY = 0; const cacheKey = (workflowId) => `workflow-published-data:${workflowId}`; let WorkflowPublishedDataService = class WorkflowPublishedDataService { constructor(logger, workflowPublishedVersionRepository, cacheService) { this.logger = logger; this.workflowPublishedVersionRepository = workflowPublishedVersionRepository; this.cacheService = cacheService; this.logger = this.logger.scoped('poll-trigger'); } async getPublishedWorkflowData(workflowId) { const record = await this.workflowPublishedVersionRepository.getPublishedVersionWithRelations(workflowId); if (!record?.publishedVersion || !record.workflow) { return null; } return { workflow: record.workflow, publishedVersion: record.publishedVersion }; } async getPublishedWorkflowDataForExecution(workflowId) { return await this.workflowPublishedVersionRepository.getPublishedVersionForExecution(workflowId); } async getCachedPublishedWorkflowDataForExecution(workflowId) { try { const cached = await this.cacheService.get(cacheKey(workflowId)); if (cached) return cached; } catch (error) { this.logger.warn('Failed to read published-version cache; falling back to the database', { workflowId, error: (0, ensure_error_1.ensureError)(error).message, }); } return await this.getPublishedWorkflowDataForExecution(workflowId); } async invalidateCache(workflowId) { await this.cacheService.delete(cacheKey(workflowId)); } async refreshCache(workflowId) { const key = cacheKey(workflowId); const data = await this.getPublishedWorkflowDataForExecution(workflowId); if (data) { await this.cacheService.set(key, data, NO_EXPIRY); } else { await this.cacheService.delete(key); } } }; exports.WorkflowPublishedDataService = WorkflowPublishedDataService; exports.WorkflowPublishedDataService = WorkflowPublishedDataService = __decorate([ (0, di_1.Service)(), __metadata("design:paramtypes", [backend_common_1.Logger, db_1.WorkflowPublishedVersionRepository, cache_service_1.CacheService]) ], WorkflowPublishedDataService); //# sourceMappingURL=workflow-published-data.service.js.map