Coretex
status.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 from enum import IntEnum
19 
20 
21 class TaskRunStatus(IntEnum):
22 
23  """
24  List of possible TaskRun statuses during the TaskRun lifetime
25  """
26 
27  queued = 1
28  preparingToStart = 2
29  inProgress = 3
30  completedWithSuccess = 4
31  completedWithError = 5
32  stopped = 6
33  stopping = 7
34  startRequested = 8
35  stopRequested = 9
36 
37  @property
38  def defaultMessage(self) -> str:
39  """
40  List of supported statuses:
41  - preparingToStart : TaskRun preparing to start
42  - completedWithSuccess : TaskRun is completed without errors
43  - completedWithError : TaskRun is completed with error
44  - stopped : TaskRun is stopped manually
45  - stopping : TaskRun is stopping
46 
47  Returns
48  -------
49  str -> Appropriate message based on TaskRun status
50 
51  Raises
52  ------
53  ValueError -> if unsupported status is provided
54  """
55 
56  if self == TaskRunStatus.preparingToStart:
57  return "Preparing to start the Task Run."
58 
59  if self == TaskRunStatus.completedWithSuccess:
60  return "Task Run completed successfully."
61 
62  if self == TaskRunStatus.completedWithError:
63  return "Task Run failed due to an error. View console output for more details."
64 
65  if self == TaskRunStatus.stopped:
66  return "User stopped the Task Run."
67 
68  if self == TaskRunStatus.stopping:
69  return "Stopping the Task Run."
70 
71  raise ValueError(f">> [Coretex] {self.name} has no default message")
72 
73  @property
74  def isFinal(self) -> bool:
75  """
76  List of final statuses:
77  - TaskRunStatus.completedWithSuccess : TaskRun finished without error
78  - TaskRunStatus.completedWithError : TaskRun finished with an error
79  - TaskRunStatus.stopped : TaskRun is manually stopped
80 
81  Returns
82  -------
83  bool -> True if a status is a final status for a run
84  """
85 
86  return (
87  self == TaskRunStatus.completedWithSuccess or
88  self == TaskRunStatus.completedWithError or
89  self == TaskRunStatus.stopped
90  )