@@ -206,12 +206,35 @@ public void registerBatchJobWatcher(Job job, String taskInstanceId, TaskResponse
206206
207207 @ Override
208208 public void onAdd (Job watchedJob ) {
209- // ignore initial add event, same as Watcher.Action.ADDED
209+ try {
210+ LogUtils .setWorkflowAndTaskInstanceIDMDC (taskRequest .getWorkflowInstanceId (),
211+ taskRequest .getTaskInstanceId ());
212+ LogUtils .setTaskInstanceLogFullPathMDC (taskRequest .getLogPath ());
213+ log .info ("event received : job:{} action:ADD" , watchedJob .getMetadata ().getName ());
214+ } finally {
215+ LogUtils .removeTaskInstanceLogFullPathMDC ();
216+ LogUtils .removeWorkflowAndTaskInstanceIdMDC ();
217+ }
210218 }
211219
212220 @ Override
213221 public void onUpdate (Job oldJob , Job watchedJob ) {
214- handleBatchJobEvent (watchedJob , taskInstanceId , taskResponse , countDownLatch );
222+ try {
223+ LogUtils .setWorkflowAndTaskInstanceIDMDC (taskRequest .getWorkflowInstanceId (),
224+ taskRequest .getTaskInstanceId ());
225+ LogUtils .setTaskInstanceLogFullPathMDC (taskRequest .getLogPath ());
226+ log .info ("event received : job:{} action:UPDATE" , watchedJob .getMetadata ().getName ());
227+ int jobStatus = getK8sJobStatus (watchedJob );
228+ log .info ("job {} status {}" , watchedJob .getMetadata ().getName (), jobStatus );
229+ if (jobStatus == TaskConstants .RUNNING_CODE ) {
230+ return ;
231+ }
232+ setTaskStatus (jobStatus , taskInstanceId , taskResponse );
233+ countDownLatch .countDown ();
234+ } finally {
235+ LogUtils .removeTaskInstanceLogFullPathMDC ();
236+ LogUtils .removeWorkflowAndTaskInstanceIdMDC ();
237+ }
215238 }
216239
217240 @ Override
@@ -250,28 +273,6 @@ public void onDelete(Job watchedJob, boolean deletedFinalStateUnknown) {
250273 }
251274 }
252275
253- private void handleBatchJobEvent (Job watchedJob ,
254- String taskInstanceId ,
255- TaskResponse taskResponse ,
256- CountDownLatch countDownLatch ) {
257- try {
258- LogUtils .setWorkflowAndTaskInstanceIDMDC (taskRequest .getWorkflowInstanceId (),
259- taskRequest .getTaskInstanceId ());
260- LogUtils .setTaskInstanceLogFullPathMDC (taskRequest .getLogPath ());
261- log .info ("event received : job:{}" , watchedJob .getMetadata ().getName ());
262- int jobStatus = getK8sJobStatus (watchedJob );
263- log .info ("job {} status {}" , watchedJob .getMetadata ().getName (), jobStatus );
264- if (jobStatus == TaskConstants .RUNNING_CODE ) {
265- return ;
266- }
267- setTaskStatus (jobStatus , taskInstanceId , taskResponse );
268- countDownLatch .countDown ();
269- } finally {
270- LogUtils .removeTaskInstanceLogFullPathMDC ();
271- LogUtils .removeWorkflowAndTaskInstanceIdMDC ();
272- }
273- }
274-
275276 private void parsePodLogOutput () {
276277 ExecutorService collectPodLogExecutorService = ThreadUtils
277278 .newSingleDaemonScheduledExecutorService ("CollectPodLogOutput-thread-" + taskRequest .getTaskName ());
0 commit comments