Browse Source

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
tags/4.0.0^0
Renat Akhmerov 1 week ago
parent
commit
dc827496ad
3 changed files with 27 additions and 15 deletions
  1. +4
    -1
      mistralclient/commands/v2/base.py
  2. +16
    -10
      mistralclient/commands/v2/tasks.py
  3. +7
    -4
      mistralclient/tests/unit/v2/test_cli_tasks.py

+ 4
- 1
mistralclient/commands/v2/base.py View File

@@ -199,11 +199,14 @@ def get_filters(parsed_args):
def get_duration_str(start_dt_str, end_dt_str):
"""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
calculated from the current time.
:return: Duration(delta) string.
"""
if not start_dt_str:
return ''

start_dt = dt.datetime.strptime(start_dt_str, '%Y-%m-%d %H:%M:%S')

if end_dt_str:

+ 16
- 10
mistralclient/commands/v2/tasks.py View File

@@ -31,15 +31,17 @@ LOG = logging.getLogger(__name__)

class TaskFormatter(base.MistralFormatter):
COLUMNS = [
('id', 'ID'),
('name', 'Name'),
('workflow_name', 'Workflow name'),
('workflow_namespace', 'Workflow namespace'),
('workflow_execution_id', 'Workflow Execution ID'),
('state', 'State'),
('state_info', 'State info'),
('created_at', 'Created at'),
('updated_at', 'Updated at'),
('id', 'ID'),
('name', 'Name'),
('workflow_name', 'Workflow name'),
('workflow_namespace', 'Workflow namespace'),
('workflow_execution_id', 'Workflow Execution ID'),
('state', 'State'),
('state_info', 'State info'),
('created_at', 'Created at'),
('started_at', 'Started at'),
('finished_at', 'Finished at'),
('duration', 'Duration', True),
]

@staticmethod
@@ -48,6 +50,8 @@ class TaskFormatter(base.MistralFormatter):
state_info = (task.state_info if not lister
else base.cut(task.state_info))

duration = base.get_duration_str(task.started_at, task.finished_at)

data = (
task.id,
task.name,
@@ -57,7 +61,9 @@ class TaskFormatter(base.MistralFormatter):
task.state,
state_info,
task.created_at,
task.updated_at or '<none>'
task.started_at or '<none>',
task.finished_at or '<none>',
duration
)
else:
data = (tuple('' for _ in range(len(TaskFormatter.COLUMNS))),)

+ 7
- 4
mistralclient/tests/unit/v2/test_cli_tasks.py View File

@@ -30,10 +30,11 @@ TASK_DICT = {
'workflow_name': 'thing',
'workflow_namespace': '',
'workflow_execution_id': '321',
'state': 'RUNNING',
'state': 'SUCCESS',
'state_info': None,
'created_at': '1',
'updated_at': '1',
'created_at': '2020-02-07 08:10:32',
'started_at': '2020-02-07 08:10:32',
'finished_at': '2020-02-07 08:10:41'
}

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)

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…
Cancel
Save