Hi,
I am getting a ton of errors when I am trying to just detect some flow that are not recently ran or skipped running due to a possible connection issue which probably happens for them to skip the schedule run and pose a risk for loss of data because of a schedule that was not properly ran.
This is my Javascript Pre hook script for that.
function checkFlowNotRunRecently(options) {
const currentTime = Date.now();
const flowId = String(options.data[0]._id || options.data[0]._integrationId || "Unknown ID");
const flowName = options.data[0].name || "Unknown Flow";
const traceKeyValue = String(options.data[0].io_custom_trace_key);
const lastExecutedAt = options.lastExecutedAt || null;
const flowDisabled = options.data[0].disabled;
let resultmessage;
let timeSinceLastRun = null;
if (flowDisabled === true) {
console.log("No Issue");
}
if (!lastExecutedAt) {
resultmessage = true;
throw new Error(`Flow "${flowName}" has NEVER been executed or lastExecutedAt is not available)`);
}
const lastExecutedTime = new Date(lastExecutedAt).getTime();
timeSinceLastRun = currentTime - lastExecutedTime;
const hoursSinceLastRun = (timeSinceLastRun / (60 * 60 * 1000)).toFixed(2);
if (timeSinceLastRun >= 24 * 60 * 60 * 1000) {
resultmessage = true;
throw new Error(`Flow "${flowName}" has NOT run in the last 24 hours(last run: ${hoursSinceLastRun} hours ago)); } else { resultmessage = false; console.log("No Issue")`);
}
options.data.forEach((record) => {
record.resultmessage = resultmessage;
record.flowId = flowId;
record.flowName = flowName;
record.lastExecutedAt = lastExecutedAt;
record.timeSinceLastRunMs = timeSinceLastRun;
record.hoursSinceLastRun = hoursSinceLastRun;
});
return options.data;
}
FYI: I am just using console.log for those areas that need no actions, i just need a specific error thrown when one flow was not ran within 24 hours. Unfortunately, some flows are repetitively being thrown as an error, having major duplicates within. Any thoughts how to solve this issue?

