blob: c3577729e4c899b6eb9bf3c8845f58055c8de13c (
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
27
28
29
30
31
32
33
34
35
36
37
38
|
from typing import Literal, Dict
from mypy_boto3_mturk.literals import EventTypeType
from pydantic import BaseModel, Field
from jb.models.custom_types import AwareDatetimeISO, AMTBoto3ID
class MTurkEvent(BaseModel):
"""
What AWS SNS will POST to our mturk_notifications endpoint (inside the request body)
"""
event_type: EventTypeType = Field(example="AssignmentSubmitted")
event_timestamp: AwareDatetimeISO = Field(example="2025-10-16T18:45:51Z")
amt_hit_id: AMTBoto3ID = Field(example="12345678901234567890")
amt_assignment_id: str = Field(
max_length=64, example="1234567890123456789012345678901234567890"
)
amt_hit_type_id: AMTBoto3ID = Field(example="09876543210987654321")
@classmethod
def from_sns(cls, data: Dict):
return cls.model_validate(
{
"event_type": data["EventType"],
"event_timestamp": cls.fix_mturk_timestamp(data["EventTimestamp"]),
"amt_hit_id": data["HITId"],
"amt_assignment_id": data["AssignmentId"],
"amt_hit_type_id": data["HITTypeId"],
}
)
@staticmethod
def fix_mturk_timestamp(ts: str) -> str:
if ts.endswith("Z") and "." not in ts:
ts = ts[:-1] + ".000Z"
return ts
|