Forge Function: Running Code After Invocation & Logs

We have a use case where we want to do some fire and forge operation in a Forge function. We want to return and run that fire and forget code in the background.

According to the documentation, you can run extra code after the function invocation: https://developer.atlassian.com/platform/forge/function-reference/nodejs-runtime/

However, this is very, very under-specified.

  • How log can it take to still run?
  • Any limits to it?
  • What happens to the logs? (They seem go missing/unreliable?)

So, we experimented with it a bit. It defiantly runs some code later on, but very unclear for how log. And the biggest issue: Logs from that later code seem to disappear into the void.
For example we have code like this:

setTimeout(()=>{ // The setTimeout is just for experimentation. 
    console.info(`Invoked later at: ${Date.now()-start}`)
    doBackgroundAction().then(_ => {
        console.info(`background action complete: ${Date.now()-start}`);
    }, e => {
        console.warn(`background action failed: ${Date.now()-start}`, e)
    });
}, 500)

Then the log entry is usually missing? Yet the action actually ran.

So, i basically want to know:

  • How long does the operation have time before it gets killed?
  • Why are the logs so unreliable for this case / or do I have to do something?
2 Likes

Why not just use a consumer module and queue up the action you want done in the background. You’ll get logs and the behavior is more deterministic.

I’d recommend that you use the https://developer.atlassian.com/platform/forge/runtime-reference/async-events-api/ for this purpose.