import pandas as pd
import datetime
from datetime import timedelta
from functools import wraps
import time
def check_exec(func):
@wraps(func)
def exe_func(*args, **kwargs):
loop_cd, step_no = func(*args, **kwargs)
exec_info_dict['loop_cd'].append(loop_cd)
exec_info_dict['step_no'].append(step_no)
start_datetime = datetime.datetime.now()
start_datetime_str = start_datetime.strftime('%Y-%m-%d %H:%M:%S')
exec_info_dict['func'].append(f"{func.__name__}")
exec_info_dict['start_dt'].append(start_datetime_str)
end_datetime = datetime.datetime.now() + timedelta(hours=9)
end_datetime_str = end_datetime.strftime('%Y-%m-%d %H:%M:%S')
operation_time = (end_datetime - start_datetime).seconds
exec_info_dict['end_dt'].append(end_datetime_str)
exec_info_dict['operation_time'].append(operation_time)
exec_info_dict['success'].append('Y')
return exe_func
# 실행 정보
exec_info_dict = {
"loop_cd": []
, "step_no": []
, "func": []
, "start_dt": []
, "end_dt": []
, "operation_time": []
, "success": []
}
@check_exec
def first(loop_cd, step_no):
time.sleep(3)
return loop_cd, step_no
@check_exec
def second(loop_cd, step_no):
time.sleep(3)
return loop_cd, step_no
@check_exec
def third(loop_cd, step_no):
time.sleep(3)
return loop_cd, step_no
loop_lst = ['0001', '0002', '0003']
for loop_cd in loop_lst :
a = first(loop_cd, step_no = '1')
b = second(loop_cd, step_no = '2')
c = third(loop_cd, step_no = '3')
pdf = pd.DataFrame.from_dict(exec_info_dict)
pdf
loop_cd step_no func ... end_datetime operation_time success
0 0001 1 first ... 2022-09-20 07:46:21 32400 Y
1 0001 2 second ... 2022-09-20 07:46:24 32400 Y
2 0001 3 third ... 2022-09-20 07:46:27 32400 Y
3 0002 1 first ... 2022-09-20 07:46:30 32400 Y
4 0002 2 second ... 2022-09-20 07:46:33 32400 Y
5 0002 3 third ... 2022-09-20 07:46:36 32400 Y
6 0003 1 first ... 2022-09-20 07:46:39 32400 Y
7 0003 2 second ... 2022-09-20 07:46:42 32400 Y
8 0003 3 third ... 2022-09-20 07:46:45 32400 Y