modmex-lambda 0.6.0__py3-none-any.whl → 0.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- #pylint: disable=C0301
1
+ import json
2
2
  import pydash
3
3
  from pydash import get
4
4
 
@@ -15,6 +15,34 @@ def from_s3(event):
15
15
  }
16
16
  )
17
17
 
18
+ def from_sqs_sns_s3(event):
19
+ """Normalize an S3 notification delivered through SNS and SQS.
20
+
21
+ An SNS message can contain more than one S3 record, so this function
22
+ returns one UOW per S3 record. The event contract is the same as
23
+ :func:`from_s3`; the transport envelopes are retained in ``record``.
24
+ """
25
+ return pydash._(event['Records']).map(
26
+ lambda sqs_record: _from_sqs_record(sqs_record)
27
+ ).flatten().value()
28
+
29
+
30
+ def _from_sqs_record(sqs_record):
31
+ sns_record = json.loads(sqs_record['body'])
32
+ s3_event = json.loads(sns_record['Message'])
33
+
34
+ return pydash.map_(
35
+ from_s3(s3_event),
36
+ lambda uow: {
37
+ **uow,
38
+ 'record': {
39
+ 'sqs': sqs_record,
40
+ 'sns': sns_record,
41
+ 's3': uow['record'],
42
+ },
43
+ },
44
+ )
45
+
18
46
  def _calculate_event_type_prefix(record):
19
47
  if record['eventName'] in ['ObjectCreated:Post','ObjectCreated:Put']:
20
48
  return 'object-created'
@@ -3,6 +3,7 @@ import os
3
3
  from datetime import datetime, timedelta, timezone
4
4
  from typing import Any, Callable, Optional
5
5
 
6
+ from pydash import get
6
7
  from reactivex import Observable, operators as ops
7
8
 
8
9
  from modmex_lambda.connectors.ieventbridge import IEventBridgeConnector
@@ -47,7 +48,15 @@ class Schedule(BaseFlavor):
47
48
  logger=logger,
48
49
  connector=connector,
49
50
  dependency_resolver=dependency_resolver,
50
- publisher_options=publisher_options,
51
+ publisher_options={
52
+ **(publisher_options or {}),
53
+ "event_field": "emit",
54
+ **(
55
+ {"source": rule["source"]}
56
+ if isinstance(rule.get("source"), str)
57
+ else {}
58
+ ),
59
+ },
51
60
  )
52
61
  self.rule = rule
53
62
 
@@ -57,14 +66,31 @@ class Schedule(BaseFlavor):
57
66
 
58
67
  def __call__(self, source: Observable):
59
68
  return source.pipe(
69
+ try_filter(self._for_collected_events),
70
+ try_map(self._normalize),
60
71
  try_filter(on_event_type(self.rule)),
61
72
  ops.do_action(print_start(self.logger)),
62
73
  try_filter(on_content(self.rule)),
63
74
  try_map(faulty(self._to_schedule_request)),
64
75
  self.scheduler_ops,
76
+ self.publisher,
65
77
  ops.do_action(print_end(self.logger)),
66
78
  )
67
79
 
80
+ @staticmethod
81
+ def _for_collected_events(uow: Uow) -> bool:
82
+ return (
83
+ get(uow, "record.eventName") == "INSERT"
84
+ and get(uow, "record.dynamodb.Keys.sk.S") == "EVENT"
85
+ )
86
+
87
+ @staticmethod
88
+ def _normalize(uow: Uow) -> Uow:
89
+ return {
90
+ **uow,
91
+ "event": get(uow, "event.raw.new.event"),
92
+ }
93
+
68
94
  def _to_schedule_request(self, uow: Uow) -> Uow:
69
95
  schedule_at = self._resolve_schedule_at(uow)
70
96
  if schedule_at.tzinfo is None:
@@ -79,9 +105,16 @@ class Schedule(BaseFlavor):
79
105
  raise ValueError("bus_arn or BUS_ARN is required.")
80
106
  if not role_arn:
81
107
  raise ValueError("role_arn or SCHEDULER_ROLE_ARN is required.")
108
+ if schedule_at <= datetime.now(timezone.utc):
109
+ return {
110
+ **uow,
111
+ "scheduled_event": scheduled_event,
112
+ "emit": scheduled_event,
113
+ }
82
114
  return {
83
115
  **uow,
84
116
  "scheduled_event": scheduled_event,
117
+ "emit": None,
85
118
  "schedule_request": {
86
119
  "Name": self._value("schedule_name", uow),
87
120
  "GroupName": self._value("group_name", uow, "default"),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modmex-lambda
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: Ultra-lightweight AWS Lambda utilities for API Gateway routing and event handling.
5
5
  Author: Modmex
6
6
  License: MIT
@@ -1188,6 +1188,10 @@ Use `schedule_at` when the deadline is already an explicit, timezone-aware
1188
1188
  is calculated from the source event's millisecond `timestamp`, not from Lambda
1189
1189
  processing time. Declare exactly one of those fields.
1190
1190
 
1191
+ If the calculated deadline has already passed when the source event is
1192
+ processed, `Schedule` does not create an invalid `at(...)` schedule. It
1193
+ publishes the deferred domain event immediately on the configured bus instead.
1194
+
1191
1195
  ### Event Hub
1192
1196
 
1193
1197
  EventBridge is a natural hub for domain events. Flavors like
@@ -77,7 +77,7 @@ modmex_lambda/stream/schedulers.py,sha256=A_wFD1e7CGFGO6--QHln8Eho08fdH5W-OVWfho
77
77
  modmex_lambda/stream/events/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
78
78
  modmex_lambda/stream/events/dynamodb.py,sha256=T1g9j4QpWC1gBYaFm11YdcQ9Ma0konHIVF48mOAD_PE,4895
79
79
  modmex_lambda/stream/events/kinesis.py,sha256=BDSO7mwAV6utXROBxbyv36fbNspwOkHpvnysmFNDz0Q,1154
80
- modmex_lambda/stream/events/s3.py,sha256=9f1sI74_tNpXHzEpAGitFRFZZKwJdqR10SQN7xPbxME,2299
80
+ modmex_lambda/stream/events/s3.py,sha256=aIaLyM2TzI3ZYHlI6cGBvJKtnkx0iiJ4KLEFNCtl9lE,3121
81
81
  modmex_lambda/stream/events/sns.py,sha256=MHtLaKKYvmhPOQjqCMgxNFXpBuYfW4wGaC1BxwWTaIw,2073
82
82
  modmex_lambda/stream/events/sqs.py,sha256=AnaIdTJA5emzPKMXG-8OQTmhmB6PrGu4zXDepcHqxNE,1470
83
83
  modmex_lambda/stream/filters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -96,7 +96,7 @@ modmex_lambda/stream/flavors/iflavor.py,sha256=KuaYO0koDCo9C8wV0nW1MV9XwZF1tvulj
96
96
  modmex_lambda/stream/flavors/job.py,sha256=enIBW5A-c-bnpzL8f6vPLfr_HbQu4ucgc_YJ08vb7FM,10155
97
97
  modmex_lambda/stream/flavors/materialize.py,sha256=-00aBf7L_egPbMzUBXAleiRVWlUQT6hbrDvL9yZrwxI,2335
98
98
  modmex_lambda/stream/flavors/s3.py,sha256=08PzZetQFZJsiEmHf6aBJXTh8FKMFJk8Ruoqojh-NvE,2133
99
- modmex_lambda/stream/flavors/schedule.py,sha256=yYJ9CD9nBW_xh8M4ZeaZDJ4tKUk3snUp3ZEjXKcF7RM,6396
99
+ modmex_lambda/stream/flavors/schedule.py,sha256=ykfEZXbCNtI6LjK99oBLRZMZXQXBX_NIydunt1By1SE,7392
100
100
  modmex_lambda/stream/flavors/sns.py,sha256=L-yRQFYzstdj53Dspn6EC_YLX-gvjfQCLLfbmE9zsHI,2009
101
101
  modmex_lambda/stream/flavors/task.py,sha256=PhRMLh4oCXv2jWw-ZoeZ8ioA40Ju9e5szcnWsBayai4,4265
102
102
  modmex_lambda/stream/flavors/update.py,sha256=QUhkXKAD18w5GT2OKcCKnkYySJyX5ao4llil-AZVLJI,6141
@@ -144,7 +144,7 @@ modmex_lambda/stream/utils/time.py,sha256=dnsL2xeWpa1FXm2p8y9rWXtICMBlCBkgLaJ_en
144
144
  modmex_lambda/stream/utils/uow.py,sha256=8WSPVE7AiHInkFDfBEeKOvdirY6GAgBoS7qkF1f1JVM,3207
145
145
  modmex_lambda/stream/utils/data_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
146
146
  modmex_lambda/stream/utils/data_classes/dynamodb.py,sha256=h_7MtUyRkvvV1r2QECrRDu7RR4Hh94SwSjc_8K2_XGM,363
147
- modmex_lambda-0.6.0.dist-info/METADATA,sha256=MQuHh4t3CGQrfPWs8HxmCwaN15y3Zf4gYcCzqmAp4Js,35220
148
- modmex_lambda-0.6.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
149
- modmex_lambda-0.6.0.dist-info/licenses/LICENSE,sha256=_C2TDTOsYeJvE4vn9VB51laKvleBKbdNnn96wJVtXhQ,1063
150
- modmex_lambda-0.6.0.dist-info/RECORD,,
147
+ modmex_lambda-0.6.1.dist-info/METADATA,sha256=lxtkHuSdAVr7P1UIv2FZ5WDX0oqewyqWITIAk46j018,35443
148
+ modmex_lambda-0.6.1.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
149
+ modmex_lambda-0.6.1.dist-info/licenses/LICENSE,sha256=_C2TDTOsYeJvE4vn9VB51laKvleBKbdNnn96wJVtXhQ,1063
150
+ modmex_lambda-0.6.1.dist-info/RECORD,,