Skip to content

Commit

Permalink
fix(batch/runner): catch all exceptions while on killing job
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois authored and brian-mulier-p committed Jul 5, 2024
1 parent 92187fe commit 04ef652
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/java/io/kestra/plugin/gcp/runner/Batch.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,12 @@ protected Map<String, Object> runnerAdditionalVars(RunContext runContext, TaskCo
private void safelyKillJob(final RunContext runContext,
final GoogleCredentials credentials,
final String jobName) {
runContext.logger().info("Killing Job {}", jobName);
// Use a dedicated BatchServiceClient, as the one used in the run method may be closed in the meantime.
try (BatchServiceClient batchServiceClient = newBatchServiceClient(credentials)) {
final Job job = batchServiceClient.getJob(jobName);
if (isTerminated(job.getStatus().getState())) {
runContext.logger().debug("Job {} is already terminated. Skip deletion request.", jobName);
// Job execution is already terminated, so we can skip deletion.
return;
}
Expand All @@ -493,9 +495,8 @@ private void safelyKillJob(final RunContext runContext,
} catch (InterruptedException e) {
runContext.logger().warn("Interrupted while deleting Job: {}", jobName);
Thread.currentThread().interrupt();
} catch (ExecutionException | IOException e) {
Throwable t = e.getCause() != null ? e.getCause() : e;
runContext.logger().warn("Failed to delete Job: {}", jobName, t);
} catch (Exception e) {
runContext.logger().warn("Failed to delete Job: {}", jobName, e);
}
}

Expand Down

0 comments on commit 04ef652

Please sign in to comment.