How can I run a task on job termination once per job?
What I'd like to do is something like:
try {
// run all regular tasks
} finally {
// run a final termination task, once per job, not per node
// the termination task shall run whether the job completed normally or was terminated early
}
In my case, the final termination task would query the Batch API and fetch the exit status of each regular task and determine the overall "success" of the job, and then write this into a database.
It seems that this is not directly possible currently. The options are:
-
Abuse the current job release tasks. Since these run per-node, the script that's executed would have to be engineered such that it is OK to run it multiple times.
-
Define the termination task as a regular task which depends on all other tasks. This would only work partly though. If the job is terminated early, then this final task would never run, which defeats the whole point.
Is there anything I'm not considering here? It seems like a fairly basic missing feature.
Your summary seems correct to me: Batch does not organically support this scenario. Your option 1 seems like the best place to start (ie: I agree with your assessment of 2).
Using JobManagementTaskSupport can solve this work.