n8n/packages/cli/src/ActivationErrors.service.ts
Iván Ovejero f2939568cf
perf(core): Optimize workflow activation errors (#8242)
At https://github.com/n8n-io/n8n/pull/8213 we introduced Redis hashes
for workflow ownership and manual webhooks...

- to remove clutter from multiple related keys at the top level,
- to improve performance by preventing serializing-deserializing, and
- to guarantee atomicity during concurrent updates in multi-main setup.

Workflow activation errors can also benefit from this. Added test
coverage as well.

To test manually, create a workflow with a trigger with an invalid
credential, edit the workflow's `active` column to `true`, and restart.
The activation error should show as a red triangle on canvas and in the
workflow list.
2024-01-05 13:06:42 +01:00

38 lines
974 B
TypeScript

import { Service } from 'typedi';
import { CacheService } from '@/services/cache/cache.service';
@Service()
export class ActivationErrorsService {
private readonly cacheKey = 'workflow-activation-errors';
constructor(private readonly cacheService: CacheService) {}
async register(workflowId: string, errorMessage: string) {
await this.cacheService.setHash(this.cacheKey, { [workflowId]: errorMessage });
}
async deregister(workflowId: string) {
await this.cacheService.deleteFromHash(this.cacheKey, workflowId);
}
async get(workflowId: string) {
const activationError = await this.cacheService.getHashValue<string>(this.cacheKey, workflowId);
if (!activationError) return null;
return activationError;
}
async getAll() {
const activationErrors = await this.cacheService.getHash<string>(this.cacheKey);
if (!activationErrors) return {};
return activationErrors;
}
async clearAll() {
await this.cacheService.delete(this.cacheKey);
}
}