diff options
Diffstat (limited to 'jb/managers/amt.py')
| -rw-r--r-- | jb/managers/amt.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/jb/managers/amt.py b/jb/managers/amt.py index 79661c7..0ec70d3 100644 --- a/jb/managers/amt.py +++ b/jb/managers/amt.py @@ -10,7 +10,7 @@ from jb.decorators import AMT_CLIENT from jb.models import AMTAccount from jb.models.assignment import Assignment from jb.models.bonus import Bonus -from jb.models.currency import USDCent +from generalresearchutils.currency import USDCent from jb.models.definitions import HitStatus from jb.models.hit import HitType, HitQuestion, Hit @@ -48,19 +48,24 @@ class AMTManager: return hit, None @classmethod - def get_hit_status(cls, amt_hit_id: str): + def get_hit_status(cls, amt_hit_id: str) -> HitStatus: res, msg = cls.get_hit_if_exists(amt_hit_id=amt_hit_id) + if res is None: + if msg is None: + return HitStatus.Unassignable + if " does not exist. (" in msg: return HitStatus.Disposed else: logging.warning(msg) return HitStatus.Unassignable + return res.status @staticmethod def create_hit_type(hit_type: HitType): - res = AMT_CLIENT.create_hit_type(**hit_type.to_api_request_body()) + res = AMT_CLIENT.create_hit_type(**hit_type.to_api_request_body()) # type: ignore hit_type.amt_hit_type_id = res["HITTypeId"] AMT_CLIENT.update_notification_settings( HITTypeId=hit_type.amt_hit_type_id, @@ -94,8 +99,10 @@ class AMTManager: @staticmethod def get_assignment(amt_assignment_id: str) -> Assignment: - # note, you CANNOT get an assignment if it has been only ACCEPTED (by the worker) - # the api is stupid. it will only show up once it is submitted + """ + You CANNOT get an Assignment if it has been only ACCEPTED (by the + worker). The api is stupid, it will only show up once it is Submitted + """ res = AMT_CLIENT.get_assignment(AssignmentId=amt_assignment_id) ass_res: AssignmentTypeDef = res["Assignment"] assignment = Assignment.from_amt_get_assignment(ass_res) @@ -158,6 +165,7 @@ class AMTManager: raise ValueError(error_msg) # elif "This HIT is currently in the state 'Reviewing'" in error_msg: # logging.warning(error_msg) + return None @staticmethod @@ -203,7 +211,7 @@ class AMTManager: return None @staticmethod - def expire_all_hits(): + def expire_all_hits() -> None: # used in testing only (or in an emergency I guess) now = datetime.now(tz=timezone.utc) paginator = AMT_CLIENT.get_paginator("list_hits") @@ -214,3 +222,4 @@ class AMTManager: AMT_CLIENT.update_expiration_for_hit( HITId=hit["HITId"], ExpireAt=now ) + return None |
