Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Moved task status lists from taskmanager to taskstate
Browse files Browse the repository at this point in the history
  • Loading branch information
maaktweluit committed Aug 13, 2019
1 parent eac4291 commit 7978de1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
24 changes: 4 additions & 20 deletions golem/task/taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,6 @@ def __init__( # pylint: disable=too-many-arguments
resource_manager
)

self.CREATING_STATUS = frozenset([
TaskStatus.creating,
TaskStatus.errorCreating,
])
self.ACTIVE_STATUS = frozenset([
TaskStatus.computing,
TaskStatus.starting,
TaskStatus.waiting,
])
self.FINISHED_STATUS = frozenset([
TaskStatus.finished,
TaskStatus.aborted,
TaskStatus.timeout,
TaskStatus.restarted,
])

self.comp_task_keeper = CompTaskKeeper(
tasks_dir,
)
Expand Down Expand Up @@ -398,11 +382,11 @@ def got_wants_to_compute(self,

def task_being_created(self, task_id: str) -> bool:
task_status = self.tasks_states[task_id].status
return task_status in self.CREATING_STATUS
return task_status.is_creating()

def task_finished(self, task_id: str) -> bool:
task_status = self.tasks_states[task_id].status
return task_status in self.FINISHED_STATUS
return task_status.is_completed()

def task_needs_computation(self, task_id: str) -> bool:
if self.task_being_created(task_id) or self.task_finished(task_id):
Expand Down Expand Up @@ -774,7 +758,7 @@ def verification_finished_():

verification_finished()

if self.tasks_states[task_id].status in self.ACTIVE_STATUS:
if self.tasks_states[task_id].status.is_active():
if not self.tasks[task_id].finished_computation():
self.tasks_states[task_id].status = TaskStatus.computing
else:
Expand Down Expand Up @@ -890,7 +874,7 @@ def check_timeouts(self):
nodes_with_timeouts = []
for t in list(self.tasks.values()):
th = t.header
if self.tasks_states[th.task_id].status not in self.ACTIVE_STATUS:
if not self.tasks_states[th.task_id].status.is_active():
continue
cur_time = int(get_timestamp_utc())
# Check subtask timeout
Expand Down
3 changes: 3 additions & 0 deletions golem/task/taskstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class TaskStatus(Enum):
timeout = "Timeout"
restarted = "Restart"

def is_creating(self) -> bool:
return self in [self.creating, self.errorCreating]

def is_completed(self) -> bool:
return self in [self.finished, self.aborted,
self.timeout, self.restarted]
Expand Down

0 comments on commit 7978de1

Please # to comment.