Skip to content

Commit

Permalink
pulling out function
Browse files Browse the repository at this point in the history
  • Loading branch information
elegantmoose committed Dec 19, 2024
1 parent 9654088 commit 858164c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions app/api/v2/managers/operation_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ async def create_potential_link(self, operation_id: str, data: dict, access: Bas
raise JsonHttpBadRequest(f'Agent {agent.paw} missing specified executor')
executor = self.build_executor(data=data.pop('executor', {}), agent=agent)
ability = self.build_ability(data=data.pop('ability', {}), executor=executor)
"""This dictionary provides plugins a way to hook into abilities at runtime"""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
self._call_ability_plugin_hooks(ability, executor)
encoded_command = self._encode_string(agent.replace(self._encode_string(data['executor']['command']),
file_svc=self.services['file_svc']))
link = Link.load(dict(command=encoded_command, plaintext_command=encoded_command, paw=agent.paw, ability=ability, executor=executor,
Expand Down Expand Up @@ -173,6 +171,11 @@ async def _construct_and_dump_source(self, source_id: str):
if not source:
source = (await self.services['data_svc'].locate('sources', match=dict(name='basic')))
return SourceSchema().dump(source[0])

async def _call_ability_plugin_hooks(self, ability, executor):
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)

async def validate_operation_state(self, data: dict, existing: Operation = None):
if not existing:
Expand Down
9 changes: 6 additions & 3 deletions app/service/planning_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ async def _generate_new_links(self, operation, agent, abilities, link_status):
executor = await agent.get_preferred_executor(ability)
if not executor:
continue
"""This dictionary provides plugins a way to hook into abilities at runtime"""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)
self._call_ability_plugin_hooks(ability, executor)
if executor.command:
link = Link.load(dict(command=self.encode_string(executor.test), paw=agent.paw, score=0,
ability=ability, executor=executor, status=link_status,
Expand Down Expand Up @@ -391,6 +389,11 @@ async def _generate_cleanup_links(self, operation, agent, link_status):
lnk.apply_id(agent.host)
links.append(lnk)
return links

async def _call_ability_plugin_hooks(self, ability, executor):
"""Calls any plugin hooks (at runtime) that exist for the ability and executor."""
for _hook, fcall in executor.HOOKS.items():
await fcall(ability, executor)

@staticmethod
async def _apply_adjustments(operation, links):
Expand Down

0 comments on commit 858164c

Please sign in to comment.