Check task execution

Hi, i needed to know if there’s any way to check if a task is executing and if it is possible to cancel that execution once it has started

Hi @jetixsolorzano

You can put console logging statements in your function and review them in the Functions section of the console.

export default function (event, ctx) {
  const uuid = uuid();

  console.log("Task started... ", uuid)
  // do code...
  console.log("Task closing... ", uuid)
}

Something like that could work. The importance of the UUID is that multiple functions could be running simultaneously, so that would help you distinguish between them.

There’s no way that we offer to cancel a task once it’s been running. However, you could maybe hack it like so.

function killSwitch() {
  if (process.env["KILL_SWITCH"] != "TRUE") return;

  throw Error('Kill switch activated! Throwing error and closing function');
}

export default function(event, ctx) {
    // Check kill switch every 1 second
    setTimeout(killSwitch, 1000)
    // Do code
}

This is hypothetical, as I’m not 100% sure if the ENVs are only loaded when the function is initialized. If not, you could take the same approach but with an async API call that reads a value and throws an error based on the response.

Let me know if this makes sense/helps.