Starting and stopping AppSignal
Since Mix tasks don’t automatically start applications, you’ll need to explicitly start the:appsignal application in your task:
Appsignal.Nif.stop/0 at the end of your task, which blocks until the extension has had enough time to flush the sent payloads to the agent before stopping.
Catching errors
To wrap errors in your task to be sent to AppSignal, add arescue block to catch errors from your code. Pass the captured exception to Appsignal.send_error/3 to report it to AppSignal. Add an after clause to your rescue block to call Appsignal.Nif.stop/0.
Appsignal.Nif.stop/0 function call flushes all the transaction data currently in the AppSignal extension to our agent. There it is transmitted on a 30 second interval. The one-off container may have exited before that time. To ensure the data is still transmitted, it needs to wait for 35 seconds.