This repository was archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 284
Task.initialize() executed in background #4324
Merged
+222
−106
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef43360
- task.rpc: run initialize_task and enqueue_new_task in another thread
mfranciszkiewicz 3d5e2f2
Linter
mfranciszkiewicz 46a9a06
Remember the reason why task creation failed
mfranciszkiewicz e74fb34
Fix the defer namespace in golem.core.deferred
mfranciszkiewicz 6594a8f
Move deferToThread import outside of 'execute' function
mfranciszkiewicz e744b63
Apply suggestions from code review
mfranciszkiewicz b217841
Fix DeferredSeq calls
mfranciszkiewicz fb586c9
Merge remote-tracking branch 'origin/develop' into bg-task-init
mfranciszkiewicz 450b183
Linter
mfranciszkiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
from golem.core import common | ||
from golem.core import deferred as golem_deferred | ||
from golem.core import simpleserializer | ||
from golem.core.deferred import DeferredSeq | ||
from golem.ethereum import exceptions as eth_exceptions | ||
from golem.model import Actor | ||
from golem.resource import resource | ||
|
@@ -402,7 +403,7 @@ def enqueue_new_task(client, task, force=False) \ | |
|
||
def _create_task_error(e, _self, task_dict, **_kwargs) \ | ||
-> typing.Tuple[None, typing.Union[str, typing.Dict]]: | ||
logger.error("Cannot create task %r: %s", task_dict, e) | ||
_self.client.task_manager.task_creation_failed(task_dict.get('id'), str(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if hasattr(e, 'to_dict'): | ||
temp_dict = rpc_utils.int_to_string(e.to_dict()) | ||
|
@@ -416,7 +417,7 @@ def _restart_task_error(e, _self, task_id, **_kwargs): | |
return None, str(e) | ||
|
||
|
||
def _restart_subtasks_error(e, _self, task_id, subtask_ids, *args, **_kwargs) \ | ||
def _restart_subtasks_error(e, _self, task_id, subtask_ids, *_args, **_kwargs) \ | ||
-> typing.Union[str, typing.Dict]: | ||
logger.error("Failed to restart subtasks. task_id: %r, subtask_ids: %r, %s", | ||
task_id, subtask_ids, e) | ||
|
@@ -470,17 +471,19 @@ def create_task(self, task_dict, force=False) \ | |
) | ||
task_id = task.header.task_id | ||
|
||
deferred = enqueue_new_task(self.client, task, force=force) | ||
# We want to return quickly from create_task without waiting for | ||
# deferred completion. | ||
deferred.addErrback( # pylint: disable=no-member | ||
DeferredSeq().push( | ||
self.task_manager.initialize_task, task | ||
).push( | ||
enqueue_new_task, self.client, task, force=force | ||
).execute().addErrback( | ||
lambda failure: _create_task_error( | ||
e=failure.value, | ||
_self=self, | ||
task_dict=task_dict, | ||
force=force | ||
), | ||
) | ||
) | ||
|
||
return task_id, None | ||
|
||
def _validate_enough_funds_to_pay_for_task( | ||
|
@@ -675,7 +678,7 @@ def restart_frame_subtasks( | |
if not frame_subtasks: | ||
logger.error('Frame restart failed, frame has no subtasks.' | ||
'task_id=%r, frame=%r', task_id, frame) | ||
return | ||
return None | ||
|
||
return self.restart_subtasks(task_id, list(frame_subtasks)) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I understand correctly that this class is supposed to compute
fn(...f3(f2(f1(None)))...)
and do it asynchronously?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and by executing those functions in a separate thread.
Since
deferred.callback
does not allow aDeferred
object to be passed as an argument (in a callback chain), this class simplyyield
s on those before passing them further.