I’m running batch jobs. Is it possible, in a task configured with a poststop lifecycle hook, to receive/forward status from the main task execution’s result?
Use case:
When the main task fails, send a message to notify that this specific task is in error.
Docs currently mention that poststop task can be used to “recover from failure”:
They are useful for performing post-processing that isn’t available in the main tasks or for recovering from failures in the main tasks.
But I’m not sure to understand how failures can be distinguished from success, in this case.
I am not aware of any Nomad native manner in which the exit status or such is passed between tasks. The approach I would potentially look at is either having the poststop task check the Nomad API for the status, or have the main task write a breadcrumb file to the shared alloc dir that the poststop task can then read to determine what actions to perform.
Thanks for this answer. That makes sense, and corresponds to the scenarios I imagined.
Considering that, for example, a failed artifact download doesn’t even hit the driver/configured command, I guess there’s no real way in the main task to write something to shared alloc dir, no matter when the failure happen - ie when initialising the task, or during its execution? It would save a roundtrip compared to checking Nomad API.