mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
fix(Salesforce Trigger Node): Update polling logic to account for Salesforce processing delay (#19377)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import moment from 'moment-timezone';
|
||||
import { DateTime } from 'luxon';
|
||||
import type {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
@@ -242,3 +243,44 @@ export function getQuery(options: IDataObject, sobject: string, returnAll: boole
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the polling start date with safety margin to account for Salesforce indexing delays
|
||||
*/
|
||||
export function getPollStartDate(lastTimeChecked: string | undefined): string {
|
||||
if (!lastTimeChecked) {
|
||||
return DateTime.now().toISO();
|
||||
}
|
||||
const safetyMarginMinutes = 15;
|
||||
return DateTime.fromISO(lastTimeChecked).minus({ minutes: safetyMarginMinutes }).toISO();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters out already processed items and manages the processed IDs list
|
||||
*/
|
||||
export function filterAndManageProcessedItems(
|
||||
responseData: IDataObject[],
|
||||
processedIds: string[],
|
||||
): { newItems: IDataObject[]; updatedProcessedIds: string[] } {
|
||||
const processedIdsSet = new Set(processedIds);
|
||||
|
||||
const newItems: IDataObject[] = [];
|
||||
const newItemIds: string[] = [];
|
||||
|
||||
for (const item of responseData) {
|
||||
if (typeof item.Id !== 'string') continue;
|
||||
|
||||
const itemId = item.Id;
|
||||
if (!processedIdsSet.has(itemId)) {
|
||||
newItems.push(item);
|
||||
newItemIds.push(itemId);
|
||||
} else {
|
||||
processedIdsSet.delete(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
const remainingProcessedIds = Array.from(processedIdsSet);
|
||||
const updatedProcessedIds = remainingProcessedIds.concat(newItemIds);
|
||||
|
||||
return { newItems, updatedProcessedIds };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user