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:
@@ -135,23 +135,35 @@ export async function nodeFetchedData(
|
||||
node: INode,
|
||||
): Promise<void> {
|
||||
if (!workflowId) return;
|
||||
// Try to insert the data loaded statistic
|
||||
try {
|
||||
await Db.collections.WorkflowStatistics.insert({
|
||||
|
||||
const hasLoadedDataPreviously = await Db.collections.WorkflowStatistics.findOne({
|
||||
select: ['count'],
|
||||
where: {
|
||||
workflowId,
|
||||
name: StatisticsNames.dataLoaded,
|
||||
count: 1,
|
||||
latestEvent: new Date(),
|
||||
});
|
||||
} catch (error) {
|
||||
// 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
|
||||
},
|
||||
});
|
||||
|
||||
if (hasLoadedDataPreviously) {
|
||||
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
|
||||
const owner = await getWorkflowOwner(workflowId);
|
||||
let metrics = {
|
||||
|
||||
Reference in New Issue
Block a user