Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/api/v2/managers/operation_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ async def update_operation_link(self, operation_id: str, link_id: str, link_data
if not link.is_valid_status(link_status):
raise JsonHttpBadRequest(f'Cannot update link {link_id} due to invalid link status.')
link.status = link_status
if link.can_ignore():
operation.add_ignored_link(link.id)
return link.display

async def create_potential_link(self, operation_id: str, data: dict, access: BaseWorld.Access):
Expand Down
16 changes: 12 additions & 4 deletions app/objects/c_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def wait_for_links_completion(self, link_ids):
for link_id in link_ids:
link = [link for link in self.chain if link.id == link_id][0]
if link.can_ignore():
self.ignored_links.add(link.id)
self.add_ignored_link(link.id)
member = [member for member in self.agents if member.paw == link.paw][0]
while not (link.finish or link.can_ignore()):
await asyncio.sleep(5)
Expand All @@ -256,6 +256,9 @@ async def is_finished(self):
def link_status(self):
return -3 if self.autonomous else -1

def add_ignored_link(self, link_id):
self.ignored_links.add(link_id)

async def active_agents(self):
active = []
for agent in self.agents:
Expand All @@ -272,7 +275,7 @@ async def get_skipped_abilities_by_agent(self, data_svc):
for agent in self.agents:
agent_skipped = defaultdict(dict)
agent_executors = agent.executors
agent_ran = set([link.ability.ability_id for link in self.chain if link.paw == agent.paw])
agent_ran = set([link.ability.ability_id for link in self.chain if link.paw == agent.paw and link.finish])
for ab in abilities_by_agent[agent.paw]['all_abilities']:
skipped = self._check_reason_skipped(agent=agent, ability=ab, agent_executors=agent_executors,
op_facts=[f.trait for f in await self.all_facts()],
Expand Down Expand Up @@ -438,8 +441,13 @@ async def _unfinished_links_for_agent(self, paw):

async def _get_all_possible_abilities_by_agent(self, data_svc):
abilities = {'all_abilities': [ab for ab_id in self.adversary.atomic_ordering
for ab in await data_svc.locate('abilities', match=dict(ability_id=ab_id))]}
return {a.paw: abilities for a in self.agents}
for ab in await data_svc.locate('abilities', match=dict(ability_id=ab_id))]}
abilities_by_agent = {a.paw: abilities for a in self.agents}
for link in self.chain:
if link.ability.ability_id not in self.adversary.atomic_ordering:
matching_abilities = await data_svc.locate('abilities', match=dict(ability_id=link.ability.ability_id))
abilities_by_agent[link.paw]['all_abilities'].extend(matching_abilities)
return abilities_by_agent

def _check_reason_skipped(self, agent, ability, op_facts, state, agent_executors, agent_ran):
if ability.ability_id in agent_ran:
Expand Down
9 changes: 9 additions & 0 deletions tests/objects/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,3 +587,12 @@ async def test_check_reason_skipped_other(self, custom_agent, test_ability, mock
assert reason['reason_id'] == Operation.Reason.OTHER.value
assert reason['ability_id'] == test_ability.ability_id
assert reason['ability_name'] == test_ability.name

async def test_add_ignored_link(self, make_test_link, operation_agent):
test_agent = operation_agent
test_link = make_test_link(9876, test_agent.paw, Link().states['DISCARD'])
op = Operation(name='test', agents=[test_agent], state='running')
op.add_ignored_link(test_link.id)
assert op.ignored_links
assert test_link.id in op.ignored_links
assert len(op.ignored_links) == 1