summaryrefslogtreecommitdiff
path: root/jb/models/event.py
diff options
context:
space:
mode:
authorMax Nanis2026-02-19 02:43:23 -0500
committerMax Nanis2026-02-19 02:43:23 -0500
commitf0f96f83c2630e890a2cbcab53f77fd4c37e1684 (patch)
treec6d2cb092e76bf5d499e0ea9949508d6b22164fd /jb/models/event.py
parent3eaa56f0306ead818f64c3d99fc6d230d9b970a4 (diff)
downloadamt-jb-master.tar.gz
amt-jb-master.zip
Models, Project files, some pytests, requirements.. etcHEADmaster
Diffstat (limited to 'jb/models/event.py')
-rw-r--r--jb/models/event.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/jb/models/event.py b/jb/models/event.py
new file mode 100644
index 0000000..c357772
--- /dev/null
+++ b/jb/models/event.py
@@ -0,0 +1,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