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

Commit

Permalink
Merge pull request #4542 from golemfactory/fix_task_status_on_error
Browse files Browse the repository at this point in the history
Fix task status when not enough funds are available
  • Loading branch information
mfranciszkiewicz authored Jul 25, 2019
2 parents e593aff + d49d4ca commit f84b06b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions golem/task/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,19 @@ def create_task(self, task_dict, force=False) \
logger.debug('force=%r', force)

task = _create_task(self.client, task_dict)
self._validate_enough_funds_to_pay_for_task(
task.subtask_price,
task.get_total_tasks(),
task.header.concent_enabled,
force
)
task_id = task.header.task_id

try:
self._validate_enough_funds_to_pay_for_task(
task.subtask_price,
task.get_total_tasks(),
task.header.concent_enabled,
force
)
except Exception as exc: # pylint: disable=broad-except
self.client.task_manager.task_creation_failed(task_id, str(exc))
raise

# Fire and forget the next steps after create_task
deferred = _prepare_task(client=self.client, task=task, force=force)
deferred.addErrback(
Expand Down
2 changes: 1 addition & 1 deletion golem/task/taskmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def add_new_task(self, task: Task, estimated_fee: int = 0) -> None:

@handle_task_key_error
def task_creation_failed(self, task_id: str, reason: str) -> None:
logger.error("Cannot create task. id=%s : %s", task_id, reason)
logger.error("Cannot create task. task_id=%s : %s", task_id, reason)

task_state = self.tasks_states[task_id]
task_state.status = TaskStatus.errorCreating
Expand Down
4 changes: 3 additions & 1 deletion tests/golem/task/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,16 @@ def setUp(self):
)

@mock.patch('twisted.internet.reactor', mock.Mock())
@mock.patch("golem.task.taskmanager.TaskManager.task_creation_failed")
@mock.patch("golem.task.rpc.prepare_and_validate_task_dict")
def test_create_task(self, mock_method, *_):
def test_create_task(self, mock_method, creation_failed, *_):
t = dummytaskstate.DummyTaskDefinition()
t.name = "test"
mock_method.side_effect = Exception("Test")

result = self.provider.create_task(t.to_dict())
mock_method.assert_called()
creation_failed.assert_called()
self.assertEqual(result, (None, "Test"))

def test_restart_task(self, *_):
Expand Down

0 comments on commit f84b06b

Please # to comment.