# ============================== # Subroutine get_task_id_via_pid # ============================== subroutine(get_task_id_via_pid( string pid, int max_time), ( # max_time specifies the maximum time to look up the task_id string task_id; int time_delay = 1000; int time_elapsed = 0; if (max_time <= time_delay) then ( max_time = time_delay + 100; ); while (task_id eq "" and (time_elapsed < max_time)) ( debug_message("\n\n@@@@ Searching for task with PID: $pid \n"); get_task_info("volatile.task_info"); debug_message("@@@@ get_task_id_via_pid() - task_info:\n" . node_as_string("volatile.task_info") . "\n"); node task; # debug_message("#### #### task_info: " . node_as_string("volatile.task_info") . "\n"); foreach task "volatile.task_info" ( if (subnode_exists(task, "pid") and (node_value(subnode_by_name(task, "pid")) eq pid)) then ( task_id = node_name(task); debug_message("@@@@ Got the task_id $task_id after $time_elapsed milliseconds\n"); # ----------------------------- # check for error and report it # ----------------------------- if (subnode_exists(task, "error_message") and (node_value(subnode_by_name(task, "error_message")) ne "")) then ( volatile.error_message = node_value(subnode_by_name(task, "error_message")); ); last; ); ); if (task_id eq "") then ( debug_message("\n@@@@ NO TASK_ID FOUND FOR PID $pid; RETRYING\n\n"); sleep_milliseconds(time_delay); ); time_elapsed = time_elapsed + time_delay; # debug_message("\n\n@@@@ get_task_id_via_pid - max_time: $max_time \n"); # debug_message("@@@@ get_task_id_via_pid - time_delay: time_delay"); # debug_message("@@@@ get_task_id_via_pid - time_elapsed: $time_elapsed \n\n"); ); debug_message("\n\n@@@@ get_task_id_via_pid(), task_id: $task_id \n"); task_id; ));