feature: 提高选择日志的select的可读性
This commit is contained in:
parent
76c5371bab
commit
ed16bd76a8
|
@ -148,9 +148,12 @@ def run_script(
|
|||
delete_apscheduler_running(job_id=job_id, start_datetime=start_datetime)
|
||||
# 删除旧的脚本文件
|
||||
script_filepath_old = glob.glob(os.path.join(tempfile.gettempdir(), 'dashgo_*'))
|
||||
script_filepath_old.sort(key=os.path.getmtime, reverse=True)
|
||||
for i in script_filepath_old[30:]: # 最多只保留30个脚本文件
|
||||
os.remove(i)
|
||||
try:
|
||||
script_filepath_old.sort(key=os.path.getmtime, reverse=True)
|
||||
for i in script_filepath_old[30:]: # 最多只保留30个脚本文件
|
||||
os.remove(i)
|
||||
except Exception as e:
|
||||
pass
|
||||
elif type == 'ssh':
|
||||
# ssh默认都认为是linux系统
|
||||
with tempfile.NamedTemporaryFile(
|
||||
|
|
|
@ -10,25 +10,30 @@ def color_job_finish_status(status):
|
|||
elif status == 'error':
|
||||
return 'red'
|
||||
elif status == 'timeout':
|
||||
return 'purple'
|
||||
elif status == 'running':
|
||||
return 'orange'
|
||||
elif status == 'running':
|
||||
return 'purple'
|
||||
else:
|
||||
raise ValueError(f'未知的status:{status}')
|
||||
|
||||
|
||||
def get_start_datetime_options_by_job_id(job_id):
|
||||
from database.sql_db.dao.dao_apscheduler import get_apscheduler_start_datetime_with_status_by_job_id
|
||||
from database.sql_db.dao.dao_apscheduler import get_apscheduler_start_finish_datetime_with_status_by_job_id
|
||||
from datetime import datetime
|
||||
|
||||
return [
|
||||
{
|
||||
'label': fac.AntdTag(
|
||||
content=f'{start_datetime:%Y-%m-%dT%H:%M:%S}',
|
||||
color=color_job_finish_status(status),
|
||||
),
|
||||
'label': [
|
||||
fac.AntdText(job_id, keyboard=True),
|
||||
f' Run Time:{start_datetime:%Y-%m-%dT%H:%M:%S} - {f"{finish_datetime:%Y-%m-%dT%H:%M:%S}" if isinstance(finish_datetime, datetime) else finish_datetime} (Duration:{f"{int((finish_datetime - start_datetime).total_seconds())}s" if isinstance(finish_datetime, datetime) else "unfinish"}) ',
|
||||
fac.AntdTag(
|
||||
content=f'Status:{status.upper()}',
|
||||
color=color_job_finish_status(status),
|
||||
),
|
||||
],
|
||||
'value': f'{start_datetime:%Y-%m-%dT%H:%M:%S.%f}',
|
||||
}
|
||||
for start_datetime, status in get_apscheduler_start_datetime_with_status_by_job_id(job_id)
|
||||
for start_datetime, finish_datetime, status in get_apscheduler_start_finish_datetime_with_status_by_job_id(job_id)
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ def render_content(menu_access: MenuAccess, **kwargs):
|
|||
fac.AntdSelect(
|
||||
id='task-log-job-id-select',
|
||||
options=[{'label': job.job_id, 'value': job.job_id} for job in get_apscheduler_all_jobs()],
|
||||
style={'width': 350},
|
||||
style={'width': 700},
|
||||
prefix=fac.AntdIcon(icon='bi-table'),
|
||||
),
|
||||
fac.AntdButton('查询执行记录', id='task-log-get-start-datetime-btn'),
|
||||
|
@ -35,13 +35,10 @@ def render_content(menu_access: MenuAccess, **kwargs):
|
|||
),
|
||||
fac.AntdSpace(
|
||||
[
|
||||
fac.AntdTooltip(
|
||||
fac.AntdSelect(
|
||||
id='task-log-start-datetime-select',
|
||||
prefix=fac.AntdIcon(icon='md-query-builder'),
|
||||
style={'width': 350},
|
||||
),
|
||||
title='绿色-成功;红色-失败;紫色-超时;黄色-正在运行',
|
||||
fac.AntdSelect(
|
||||
id='task-log-start-datetime-select',
|
||||
prefix=fac.AntdIcon(icon='md-query-builder'),
|
||||
style={'width': 700},
|
||||
),
|
||||
fac.AntdButton('查询执行日志', id='task-log-get-log-btn'),
|
||||
fac.AntdSwitch(
|
||||
|
|
|
@ -22,19 +22,19 @@ def select_last_log_from_job_id(job_id: str, accept_timedelta: timedelta) -> str
|
|||
raise Exception('Job log not found') from e
|
||||
|
||||
|
||||
def get_apscheduler_start_datetime_with_status_by_job_id(job_id: str) -> datetime:
|
||||
def get_apscheduler_start_finish_datetime_with_status_by_job_id(job_id: str) -> datetime:
|
||||
"""查询指定job_id的开始时间"""
|
||||
try:
|
||||
result_running = (
|
||||
ApschedulerRunning.select(ApschedulerRunning.start_datetime).where(ApschedulerRunning.job_id == job_id).distinct().order_by(ApschedulerRunning.start_datetime.desc())
|
||||
)
|
||||
result_done = (
|
||||
ApschedulerResults.select(ApschedulerResults.start_datetime, ApschedulerResults.status)
|
||||
ApschedulerResults.select(ApschedulerResults.start_datetime, ApschedulerResults.finish_datetime, ApschedulerResults.status)
|
||||
.where(ApschedulerResults.job_id == job_id)
|
||||
.order_by(ApschedulerResults.start_datetime.desc())
|
||||
)
|
||||
start_datetimes_running = [(i.start_datetime, 'running') for i in result_running]
|
||||
start_datetimes_done = [(i.start_datetime, i.status) for i in result_done]
|
||||
start_datetimes_running = [(i.start_datetime, '...', 'running') for i in result_running]
|
||||
start_datetimes_done = [(i.start_datetime, i.finish_datetime, i.status) for i in result_done]
|
||||
return [*start_datetimes_running, *start_datetimes_done]
|
||||
except DoesNotExist as e:
|
||||
raise Exception('Job start datetime not found') from e
|
||||
|
|
Loading…
Reference in New Issue