Batch icon indicating copy to clipboard operation
Batch copied to clipboard

How can I run a task on job termination once per job?

Open letmaik opened this issue 7 years ago • 2 comments

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:

  1. 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.

  2. 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.

letmaik avatar Jul 09 '18 08:07 letmaik

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).

darylmsft avatar Jul 12 '18 19:07 darylmsft

Using JobManagementTaskSupport can solve this work.

carogonzalezzapata avatar Sep 16 '21 16:09 carogonzalezzapata