Skip to content

Commit

Permalink
Resolve MTurkUnit expiration bugs (#382)
Browse files Browse the repository at this point in the history
* Cleaning up some bugs around MTurk EXPIRED status

* Ensure all exits occur
  • Loading branch information
JackUrb authored Jan 29, 2021
1 parent f74f31a commit 1a37f05
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions mephisto/abstractions/providers/mturk/mturk_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1a37f05

Please sign in to comment.