in mephisto/data_model/unit.py [0:0]
def get_status(self) -> str:
"""
Get the status of this unit, as determined by whether there's
a worker working on it at the moment, and any other possible states. Should
return one of UNIT_STATUSES
Accurate status is crowd-provider dependent, and thus this method should be
defined in the child class to ensure that the local record matches
the ground truth in the provider
"""
from mephisto.abstractions.blueprint import AgentState
db_status = self.db_status
# Expiration is a terminal state, and shouldn't be changed
if db_status == AssignmentState.EXPIRED:
return db_status
computed_status = AssignmentState.LAUNCHED
agent = self.get_assigned_agent()
if agent is None:
row = self.db.get_unit(self.db_id)
computed_status = row["status"]
else:
agent_status = agent.get_status()
if agent_status == AgentState.STATUS_NONE:
computed_status = AssignmentState.LAUNCHED
elif agent_status in [
AgentState.STATUS_ACCEPTED,
AgentState.STATUS_ONBOARDING,
AgentState.STATUS_PARTNER_DISCONNECT,
AgentState.STATUS_WAITING,
AgentState.STATUS_IN_TASK,
]:
computed_status = AssignmentState.ASSIGNED
elif agent_status in [AgentState.STATUS_COMPLETED]:
computed_status = AssignmentState.COMPLETED
elif agent_status in [AgentState.STATUS_SOFT_REJECTED]:
computed_status = AssignmentState.SOFT_REJECTED
elif agent_status in [AgentState.STATUS_EXPIRED]:
computed_status = AssignmentState.EXPIRED
elif agent_status in [
AgentState.STATUS_DISCONNECT,
AgentState.STATUS_RETURNED,
AgentState.STATUS_TIMEOUT,
]:
# Still assigned, as we expect the task launcher to explicitly
# update our status to expired or to remove the agent
computed_status = AssignmentState.ASSIGNED
elif agent_status == AgentState.STATUS_APPROVED:
computed_status = AssignmentState.ACCEPTED
elif agent_status == AgentState.STATUS_REJECTED:
computed_status = AssignmentState.REJECTED
if computed_status != db_status:
self.set_db_status(computed_status)
return computed_status