From 1a37f0552669ccf8ada3b0ef547da89235c4b82d Mon Sep 17 00:00:00 2001 From: Jack Urbanek Date: Fri, 29 Jan 2021 11:51:57 -0500 Subject: [PATCH] Resolve MTurkUnit expiration bugs (#382) * Cleaning up some bugs around MTurk EXPIRED status * Ensure all exits occur --- .../providers/mturk/mturk_unit.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mephisto/abstractions/providers/mturk/mturk_unit.py b/mephisto/abstractions/providers/mturk/mturk_unit.py index 39dc719b2..b22fe9822 100644 --- a/mephisto/abstractions/providers/mturk/mturk_unit.py +++ b/mephisto/abstractions/providers/mturk/mturk_unit.py @@ -107,8 +107,9 @@ def clear_assigned_agent(self) -> None: def get_status(self) -> str: """Get status for this unit directly from MTurk, fall back on local info""" - if self.db_status in [ - AssignmentState.CREATED, + if self.db_status == AssignmentState.CREATED: + return super().get_status() + elif self.db_status in [ AssignmentState.ACCEPTED, AssignmentState.EXPIRED, AssignmentState.SOFT_REJECTED, @@ -164,16 +165,19 @@ def get_status(self) -> str: raise Exception(f"Unexpected HIT status {hit_data['HITStatus']}") if external_status != local_status: - if ( - local_status == AssignmentState.ASSIGNED - and external_status == AssignmentState.LAUNCHED - ): - # Treat this as a return event, this hit is now doable by someone else + if local_status == AssignmentState.ASSIGNED and external_status in [ + AssignmentState.LAUNCHED, + AssignmentState.EXPIRED, + ]: + # Treat this as a return event, this hit may be doable by someone else agent = self.get_assigned_agent() if agent is not None: # mark the agent as having returned the HIT, to # free any running tasks and have Blueprint decide on cleanup. agent.update_status(AgentState.STATUS_RETURNED) + if external_status == AssignmentState.EXPIRED: + # If we're expired, then it won't be doable, and we should update + self.set_db_status(external_status) else: self.set_db_status(external_status) @@ -212,6 +216,7 @@ def expire(self) -> float: # amount of time we granted for working on this assignment if self.assignment_time_in_seconds is not None: delay = self.assignment_time_in_seconds + logger.debug(f"Expiring a unit that is ASSIGNED after delay {delay}") mturk_hit_id = self.get_mturk_hit_id() requester = self.get_requester() client = self._get_client(requester._requester_name)