You can add the following to your task to catch timeouts and high memory usage.
export async function run(event) {
this.on('beforeTimeout', () => {
// The task is about to timeout, just return.
// You can also report errors to log services
return;
});
this.on('highMemory', () => {
// The task is reaching the memory threshold, just return.
// You can also report errors to log services
return;
});
}
If the beforeTimeout
or highMemory
events trigger, one should consider changing the task or enqueue another task to continue.