Hi Developers,
We are trying to prevent a CloudCode task from retrying when it times out. We have successfully registered the before Timeout and we can see that it is indeed being triggered. We are however not sure how to stop the task once this is triggered. We tried to throw an error for the task to fail, but this just displays the error and does not stop the task. How would we stop the task?
Existing code:
this.on('beforeTimeout', () => {
rollbar.critical(`${CloudCode.task.name} - Script timeout imminent!`, { custom: { context: JSON.parse(JSON.stringify(this)), params: params } });
throw Error (`${CloudCode.task.name} - Script timeout imminent!`);
console.log("Error: Script timeout imminent! Stopping the task now.");
return;
});
Output:
07:05:21.326 [TASK:ERROR] Uncaught: Error: api_validate_bank_heartbeat - Script timeout imminent!
at TaskContext.Error (/var/task/app/cloudcode/api_validate_bank_heartbeat/index.js:33:15)
at TaskContext.emit (events.js:314:20)
at TaskMonitor.collect (/var/task/app/cloudcode/api_validate_bank_heartbeat/node_modules/@journeyapps/cloudcode/src/TaskMonitor.ts:54:12)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
07:05:21.419 [TASK:WARN] WARNING: The task is running over the time limit. Reduce the amount of work done per task.
07:05:21.422 [TASK:ERROR] Uncaught: Error: api_validate_bank_heartbeat - Script timeout imminent!
at TaskContext.Error (/var/task/app/cloudcode/api_validate_bank_heartbeat/index.js:33:15)
at TaskContext.emit (events.js:314:20)
at TaskMonitor.collect (/var/task/app/cloudcode/api_validate_bank_heartbeat/node_modules/@journeyapps/cloudcode/src/TaskMonitor.ts:54:12)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
07:05:21.520 [TASK:WARN] WARNING: The task is running over the time limit. Reduce the amount of work done per task.
07:05:21.523 [TASK:ERROR] Uncaught: Error: api_validate_bank_heartbeat - Script timeout imminent!
at TaskContext.Error (/var/task/app/cloudcode/api_validate_bank_heartbeat/index.js:33:15)
at TaskContext.emit (events.js:314:20)
at TaskMonitor.collect (/var/task/app/cloudcode/api_validate_bank_heartbeat/node_modules/@journeyapps/cloudcode/src/TaskMonitor.ts:54:12)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
07:05:21.620 [TASK:WARN] WARNING: The task is running over the time limit. Reduce the amount of work done per task.
07:05:21.622 [TASK:ERROR] Uncaught: Error: api_validate_bank_heartbeat - Script timeout imminent!
at TaskContext.Error (/var/task/app/cloudcode/api_validate_bank_heartbeat/index.js:33:15)
at TaskContext.emit (events.js:314:20)
at TaskMonitor.collect (/var/task/app/cloudcode/api_validate_bank_heartbeat/node_modules/@journeyapps/cloudcode/src/TaskMonitor.ts:54:12)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)