Add "duration" to task executions printed by CLI commands
* Added "started_at" and "finished_at" to task executions' printout. * Added "duration" to task executions that's calculated as a delta between "finished_at" and "started_at". * Removed "updated_at" from task executions printout since it doesn't carry any relevant info for a user, "finished_at" makes more sense. Change-Id: Ie0bd01135548bc9fb5137368a1933d7b8b3c11e5
This commit is contained in:
parent
084b6d57ce
commit
dc827496ad
|
@ -199,11 +199,14 @@ def get_filters(parsed_args):
|
||||||
def get_duration_str(start_dt_str, end_dt_str):
|
def get_duration_str(start_dt_str, end_dt_str):
|
||||||
"""Builds a human friendly duration string.
|
"""Builds a human friendly duration string.
|
||||||
|
|
||||||
:param start_dt_str: Start date time as an ISO string. Must not be empty.
|
:param start_dt_str: Start date time as an ISO string.
|
||||||
:param end_dt_str: End date time as an ISO string. If empty, duration is
|
:param end_dt_str: End date time as an ISO string. If empty, duration is
|
||||||
calculated from the current time.
|
calculated from the current time.
|
||||||
:return: Duration(delta) string.
|
:return: Duration(delta) string.
|
||||||
"""
|
"""
|
||||||
|
if not start_dt_str:
|
||||||
|
return ''
|
||||||
|
|
||||||
start_dt = dt.datetime.strptime(start_dt_str, '%Y-%m-%d %H:%M:%S')
|
start_dt = dt.datetime.strptime(start_dt_str, '%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
if end_dt_str:
|
if end_dt_str:
|
||||||
|
|
|
@ -31,15 +31,17 @@ LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TaskFormatter(base.MistralFormatter):
|
class TaskFormatter(base.MistralFormatter):
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
('id', 'ID'),
|
('id', 'ID'),
|
||||||
('name', 'Name'),
|
('name', 'Name'),
|
||||||
('workflow_name', 'Workflow name'),
|
('workflow_name', 'Workflow name'),
|
||||||
('workflow_namespace', 'Workflow namespace'),
|
('workflow_namespace', 'Workflow namespace'),
|
||||||
('workflow_execution_id', 'Workflow Execution ID'),
|
('workflow_execution_id', 'Workflow Execution ID'),
|
||||||
('state', 'State'),
|
('state', 'State'),
|
||||||
('state_info', 'State info'),
|
('state_info', 'State info'),
|
||||||
('created_at', 'Created at'),
|
('created_at', 'Created at'),
|
||||||
('updated_at', 'Updated at'),
|
('started_at', 'Started at'),
|
||||||
|
('finished_at', 'Finished at'),
|
||||||
|
('duration', 'Duration', True),
|
||||||
]
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -48,6 +50,8 @@ class TaskFormatter(base.MistralFormatter):
|
||||||
state_info = (task.state_info if not lister
|
state_info = (task.state_info if not lister
|
||||||
else base.cut(task.state_info))
|
else base.cut(task.state_info))
|
||||||
|
|
||||||
|
duration = base.get_duration_str(task.started_at, task.finished_at)
|
||||||
|
|
||||||
data = (
|
data = (
|
||||||
task.id,
|
task.id,
|
||||||
task.name,
|
task.name,
|
||||||
|
@ -57,7 +61,9 @@ class TaskFormatter(base.MistralFormatter):
|
||||||
task.state,
|
task.state,
|
||||||
state_info,
|
state_info,
|
||||||
task.created_at,
|
task.created_at,
|
||||||
task.updated_at or '<none>'
|
task.started_at or '<none>',
|
||||||
|
task.finished_at or '<none>',
|
||||||
|
duration
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
data = (tuple('' for _ in range(len(TaskFormatter.COLUMNS))),)
|
data = (tuple('' for _ in range(len(TaskFormatter.COLUMNS))),)
|
||||||
|
|
|
@ -30,10 +30,11 @@ TASK_DICT = {
|
||||||
'workflow_name': 'thing',
|
'workflow_name': 'thing',
|
||||||
'workflow_namespace': '',
|
'workflow_namespace': '',
|
||||||
'workflow_execution_id': '321',
|
'workflow_execution_id': '321',
|
||||||
'state': 'RUNNING',
|
'state': 'SUCCESS',
|
||||||
'state_info': None,
|
'state_info': None,
|
||||||
'created_at': '1',
|
'created_at': '2020-02-07 08:10:32',
|
||||||
'updated_at': '1',
|
'started_at': '2020-02-07 08:10:32',
|
||||||
|
'finished_at': '2020-02-07 08:10:41'
|
||||||
}
|
}
|
||||||
|
|
||||||
TASK_SUB_WF_EXEC = Execution(
|
TASK_SUB_WF_EXEC = Execution(
|
||||||
|
@ -81,7 +82,9 @@ TASK_WITH_RESULT = tasks.Task(mock, TASK_WITH_RESULT_DICT)
|
||||||
TASK_WITH_PUBLISHED = tasks.Task(mock, TASK_WITH_PUBLISHED_DICT)
|
TASK_WITH_PUBLISHED = tasks.Task(mock, TASK_WITH_PUBLISHED_DICT)
|
||||||
|
|
||||||
EXPECTED_TASK_RESULT = (
|
EXPECTED_TASK_RESULT = (
|
||||||
'123', 'some', 'thing', '', '321', 'RUNNING', None, '1', '1'
|
'123', 'some', 'thing', '', '321', 'SUCCESS', None,
|
||||||
|
'2020-02-07 08:10:32', '2020-02-07 08:10:32',
|
||||||
|
'2020-02-07 08:10:41', '0:00:09'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue