Skip to content

Commit

Permalink
publish task metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanthasf committed Jun 23, 2024
1 parent 6782b1b commit 24edb61
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pilot/pilot_compute_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def __init__(self, metrics_file_name, batch_job=None, cluster_manager=None):


def cancel(self):
# self.cluster_manager.cancel()
if self.client:
self.client.close()
if self.batch_job:
self.batch_job.cancel()

Expand All @@ -141,20 +142,28 @@ def submit_task(self, task_name, func, *args, **kwargs):
'submit_time': datetime.now(),
'wait_time_secs': None,
'completion_time': None,
'execution_ms': None
'execution_ms': None,
'status': None,
'error_msg': None,
}

def task_func(metrics_fn, *args, **kwargs):
metrics["wait_time_secs"] = (datetime.now()-metrics["submit_time"]).total_seconds()

task_execution_start_time = time.time()
result = func(*args, **kwargs)
try:
result = func(*args, **kwargs)
metrics["status"] = "SUCCESS"
except Exception as e:
metrics["status"] = "FAILED"
metrics["error_msg"] = str(e)


metrics["completion_time"] = datetime.now()
metrics["execution_ms"] = time.time() - task_execution_start_time

with open(metrics_fn, 'a', newline='') as csvfile:
fieldnames = ['task_id', 'submit_time', 'wait_time_secs', 'completion_time', 'execution_ms']
fieldnames = ['task_id', 'submit_time', 'wait_time_secs', 'completion_time', 'execution_ms', 'status', 'error_msg']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

if csvfile.tell() == 0:
Expand Down

0 comments on commit 24edb61

Please sign in to comment.