Skip to content

Commit 858164c

Browse files
committed
pulling out function
1 parent 9654088 commit 858164c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app/api/v2/managers/operation_api_manager.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ async def create_potential_link(self, operation_id: str, data: dict, access: Bas
100100
raise JsonHttpBadRequest(f'Agent {agent.paw} missing specified executor')
101101
executor = self.build_executor(data=data.pop('executor', {}), agent=agent)
102102
ability = self.build_ability(data=data.pop('ability', {}), executor=executor)
103-
"""This dictionary provides plugins a way to hook into abilities at runtime"""
104-
for _hook, fcall in executor.HOOKS.items():
105-
await fcall(ability, executor)
103+
self._call_ability_plugin_hooks(ability, executor)
106104
encoded_command = self._encode_string(agent.replace(self._encode_string(data['executor']['command']),
107105
file_svc=self.services['file_svc']))
108106
link = Link.load(dict(command=encoded_command, plaintext_command=encoded_command, paw=agent.paw, ability=ability, executor=executor,
@@ -173,6 +171,11 @@ async def _construct_and_dump_source(self, source_id: str):
173171
if not source:
174172
source = (await self.services['data_svc'].locate('sources', match=dict(name='basic')))
175173
return SourceSchema().dump(source[0])
174+
175+
async def _call_ability_plugin_hooks(self, ability, executor):
176+
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
177+
for _hook, fcall in executor.HOOKS.items():
178+
await fcall(ability, executor)
176179

177180
async def validate_operation_state(self, data: dict, existing: Operation = None):
178181
if not existing:

app/service/planning_svc.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,7 @@ async def _generate_new_links(self, operation, agent, abilities, link_status):
351351
executor = await agent.get_preferred_executor(ability)
352352
if not executor:
353353
continue
354-
"""This dictionary provides plugins a way to hook into abilities at runtime"""
355-
for _hook, fcall in executor.HOOKS.items():
356-
await fcall(ability, executor)
354+
self._call_ability_plugin_hooks(ability, executor)
357355
if executor.command:
358356
link = Link.load(dict(command=self.encode_string(executor.test), paw=agent.paw, score=0,
359357
ability=ability, executor=executor, status=link_status,
@@ -391,6 +389,11 @@ async def _generate_cleanup_links(self, operation, agent, link_status):
391389
lnk.apply_id(agent.host)
392390
links.append(lnk)
393391
return links
392+
393+
async def _call_ability_plugin_hooks(self, ability, executor):
394+
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
395+
for _hook, fcall in executor.HOOKS.items():
396+
await fcall(ability, executor)
394397

395398
@staticmethod
396399
async def _apply_adjustments(operation, links):

0 commit comments

Comments
 (0)