mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Cache tasks as they are queued instead of en masse (#34752)
* Cache tasks as they are queued instead of en masse This also moves the task caching from the PlayIterator to the StrategyBase class, where it makes more sense (and makes it easier to not have to change the strategy class methods leading to an API change). Fixes #31673 * Cleaning up unit tests due to 502ca780
This commit is contained in:
@@ -153,8 +153,6 @@ class PlayIterator:
|
||||
self._blocks = []
|
||||
self._variable_manager = variable_manager
|
||||
|
||||
self._task_uuid_cache = dict()
|
||||
|
||||
# Default options to gather
|
||||
gather_subset = play_context.gather_subset
|
||||
gather_timeout = play_context.gather_timeout
|
||||
@@ -242,16 +240,10 @@ class PlayIterator:
|
||||
return self._host_states[host.name].copy()
|
||||
|
||||
def cache_block_tasks(self, block):
|
||||
def _cache_portion(p):
|
||||
for t in p:
|
||||
if isinstance(t, Block):
|
||||
self.cache_block_tasks(t)
|
||||
elif t._uuid not in self._task_uuid_cache:
|
||||
self._task_uuid_cache[t._uuid] = t
|
||||
|
||||
for portion in (block.block, block.rescue, block.always):
|
||||
if portion is not None:
|
||||
_cache_portion(portion)
|
||||
# now a noop, we've changed the way we do caching and finding of
|
||||
# original task entries, but just in case any 3rd party strategies
|
||||
# are using this we're leaving it here for now
|
||||
return
|
||||
|
||||
def get_next_task_for_host(self, host, peek=False):
|
||||
|
||||
@@ -520,19 +512,8 @@ class PlayIterator:
|
||||
return self._check_failed_state(s)
|
||||
|
||||
def get_original_task(self, host, task):
|
||||
'''
|
||||
Finds the task in the task list which matches the UUID of the given task.
|
||||
The executor engine serializes/deserializes objects as they are passed through
|
||||
the different processes, and not all data structures are preserved. This method
|
||||
allows us to find the original task passed into the executor engine.
|
||||
'''
|
||||
|
||||
if isinstance(task, Task):
|
||||
the_uuid = task._uuid
|
||||
else:
|
||||
the_uuid = task
|
||||
|
||||
return self._task_uuid_cache.get(the_uuid, None)
|
||||
# now a noop because we've changed the way we do caching
|
||||
return (None, None)
|
||||
|
||||
def _insert_tasks_into_state(self, state, task_list):
|
||||
# if we've failed at all, or if the task list is empty, just return the current state
|
||||
@@ -569,6 +550,4 @@ class PlayIterator:
|
||||
return state
|
||||
|
||||
def add_tasks(self, host, task_list):
|
||||
for b in task_list:
|
||||
self.cache_block_tasks(b)
|
||||
self._host_states[host.name] = self._insert_tasks_into_state(self.get_host_state(host), task_list)
|
||||
|
||||
Reference in New Issue
Block a user