mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
fix: Prevent unnecessary error messages also for data loaded flag (#6201)
* fix: Prevent unnecessary error messages also for data loaded flag * refactor: Search if data has been loaded before trying to save and fire other events * fix broken test * fix lint issue
This commit is contained in:
parent
f3bc6f19b6
commit
d5e62ff096
|
@ -135,23 +135,35 @@ export async function nodeFetchedData(
|
||||||
node: INode,
|
node: INode,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!workflowId) return;
|
if (!workflowId) return;
|
||||||
// Try to insert the data loaded statistic
|
|
||||||
try {
|
const hasLoadedDataPreviously = await Db.collections.WorkflowStatistics.findOne({
|
||||||
await Db.collections.WorkflowStatistics.insert({
|
select: ['count'],
|
||||||
|
where: {
|
||||||
workflowId,
|
workflowId,
|
||||||
name: StatisticsNames.dataLoaded,
|
name: StatisticsNames.dataLoaded,
|
||||||
count: 1,
|
},
|
||||||
latestEvent: new Date(),
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
if (hasLoadedDataPreviously) {
|
||||||
// if it's a duplicate key error then that's fine, otherwise throw the error
|
|
||||||
if (!(error instanceof QueryFailedError)) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
// If it is a query failed error, we return
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to insert the data loaded statistic
|
||||||
|
try {
|
||||||
|
await Db.collections.WorkflowStatistics.createQueryBuilder('workflowStatistics')
|
||||||
|
.insert()
|
||||||
|
.values({
|
||||||
|
workflowId,
|
||||||
|
name: StatisticsNames.dataLoaded,
|
||||||
|
count: 1,
|
||||||
|
latestEvent: new Date(),
|
||||||
|
})
|
||||||
|
.orIgnore()
|
||||||
|
.execute();
|
||||||
|
} catch (error) {
|
||||||
|
LoggerProxy.warn('Failed saving loaded data statistics');
|
||||||
|
}
|
||||||
|
|
||||||
// Compile the metrics since this was a new data loaded event
|
// Compile the metrics since this was a new data loaded event
|
||||||
const owner = await getWorkflowOwner(workflowId);
|
const owner = await getWorkflowOwner(workflowId);
|
||||||
let metrics = {
|
let metrics = {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import type { IRun, WorkflowExecuteMode } from 'n8n-workflow';
|
import type { IRun, WorkflowExecuteMode } from 'n8n-workflow';
|
||||||
import { LoggerProxy } from 'n8n-workflow';
|
import { LoggerProxy } from 'n8n-workflow';
|
||||||
import { QueryFailedError } from 'typeorm';
|
|
||||||
import { mock } from 'jest-mock-extended';
|
import { mock } from 'jest-mock-extended';
|
||||||
|
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import * as Db from '@/Db';
|
import * as Db from '@/Db';
|
||||||
import { User } from '@db/entities/User';
|
import { User } from '@db/entities/User';
|
||||||
|
import { StatisticsNames } from '@db/entities/WorkflowStatistics';
|
||||||
import type { WorkflowStatistics } from '@db/entities/WorkflowStatistics';
|
import type { WorkflowStatistics } from '@db/entities/WorkflowStatistics';
|
||||||
import type { WorkflowStatisticsRepository } from '@db/repositories';
|
import type { WorkflowStatisticsRepository } from '@db/repositories';
|
||||||
import { nodeFetchedData, workflowExecutionCompleted } from '@/events/WorkflowStatistics';
|
import { nodeFetchedData, workflowExecutionCompleted } from '@/events/WorkflowStatistics';
|
||||||
|
@ -15,6 +15,7 @@ import { InternalHooks } from '@/InternalHooks';
|
||||||
|
|
||||||
import { mockInstance } from '../integration/shared/utils';
|
import { mockInstance } from '../integration/shared/utils';
|
||||||
import { UserService } from '@/user/user.service';
|
import { UserService } from '@/user/user.service';
|
||||||
|
import { WorkflowEntity } from '@/databases/entities/WorkflowEntity';
|
||||||
|
|
||||||
jest.mock('@/Db', () => {
|
jest.mock('@/Db', () => {
|
||||||
return {
|
return {
|
||||||
|
@ -202,8 +203,14 @@ describe('Events', () => {
|
||||||
|
|
||||||
test('should not send metrics for entries that already have the flag set', async () => {
|
test('should not send metrics for entries that already have the flag set', async () => {
|
||||||
// Fetch data for workflow 2 which is set up to not be altered in the mocks
|
// Fetch data for workflow 2 which is set up to not be altered in the mocks
|
||||||
workflowStatisticsRepository.insert.mockImplementationOnce(() => {
|
workflowStatisticsRepository.findOne.mockImplementationOnce(async () => {
|
||||||
throw new QueryFailedError('invalid insert', [], '');
|
return {
|
||||||
|
count: 1,
|
||||||
|
name: StatisticsNames.dataLoaded,
|
||||||
|
latestEvent: new Date(),
|
||||||
|
workflowId: '2',
|
||||||
|
workflow: new WorkflowEntity(),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
const workflowId = '1';
|
const workflowId = '1';
|
||||||
const node = {
|
const node = {
|
||||||
|
|
Loading…
Reference in a new issue