forked from dask/distributed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify that Worker.story() can request arbitrary log tags
Moved out of dask#6342
- Loading branch information
1 parent
715d7be
commit 038fb72
Showing
4 changed files
with
49 additions
and
29 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable | ||
|
||
|
||
def scheduler_story(keys: set, transition_log: Iterable) -> list: | ||
def scheduler_story( | ||
keys_or_stimuli: set[str], transition_log: Iterable[tuple] | ||
) -> list[tuple]: | ||
"""Creates a story from the scheduler transition log given a set of keys | ||
describing tasks or stimuli. | ||
Parameters | ||
---------- | ||
keys : set | ||
A set of task `keys` or `stimulus_id`'s | ||
keys_or_stimuli : set[str] | ||
Task keys or stimulus_id's | ||
log : iterable | ||
The scheduler transition log | ||
Returns | ||
------- | ||
story : list | ||
story : list[tuple] | ||
""" | ||
return [t for t in transition_log if t[0] in keys or keys.intersection(t[3])] | ||
return [ | ||
t | ||
for t in transition_log | ||
if t[0] in keys_or_stimuli or keys_or_stimuli.intersection(t[3]) | ||
] | ||
|
||
|
||
def worker_story(keys: set, log: Iterable) -> list: | ||
def worker_story(keys_or_tags: set[str], log: Iterable[tuple]) -> list: | ||
"""Creates a story from the worker log given a set of keys | ||
describing tasks or stimuli. | ||
Parameters | ||
---------- | ||
keys : set | ||
A set of task `keys` or `stimulus_id`'s | ||
keys_or_tags : set[str] | ||
Task keys or arbitrary tags from the transition log, e.g. stimulus_id's | ||
log : iterable | ||
The worker log | ||
Returns | ||
------- | ||
story : list | ||
story : list[str] | ||
""" | ||
return [ | ||
msg | ||
for msg in log | ||
if any(key in msg for key in keys) | ||
if any(key in msg for key in keys_or_tags) | ||
or any( | ||
key in c for key in keys for c in msg if isinstance(c, (tuple, list, set)) | ||
key in c | ||
for key in keys_or_tags | ||
for c in msg | ||
if isinstance(c, (tuple, list, set)) | ||
) | ||
] |
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