aboutsummaryrefslogtreecommitdiff
path: root/jb/flow/maintenance.py
blob: 5dc9ceaa8f40abd64d9f04390a286b3faafa63d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from typing import Optional

from jb.decorators import HM
from jb.flow.monitoring import emit_hit_event
from jb.managers.amt import AMTManager
from jb.models.definitions import HitStatus


def check_hit_status(
    amt_hit_id: str, amt_hit_type_id: str, reason: Optional[str] = None
) -> HitStatus:
    """
    (this used to be called "process_hit")
    Request information from Amazon regarding the status of a HIT ID. Update the local state from
    that response.
    """
    hit_status = AMTManager.get_hit_status(amt_hit_id=amt_hit_id)
    # We're assuming that in the db this Hit is marked as Assignable, or else we wouldn't
    #   have called this function.
    if hit_status != HitStatus.Assignable:
        # todo: should update also assignment_pending_count, assignment_available_count, assignment_completed_count
        HM.update_status(amt_hit_id=amt_hit_id, hit_status=hit_status)
        emit_hit_event(
            status=hit_status, amt_hit_type_id=amt_hit_type_id, reason=reason
        )
    return hit_status