async-lambda-unstable 0.4.7__tar.gz → 0.4.9__tar.gz
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.
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/PKG-INFO +1 -1
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/__init__.py +1 -1
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/cli.py +4 -1
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/controller.py +73 -3
- async-lambda-unstable-0.4.9/async_lambda/models/events/managed_sqs_batch_event.py +16 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/mock/mock_event.py +30 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/task.py +77 -30
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/PKG-INFO +1 -1
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/SOURCES.txt +1 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/README.md +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/build_config.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/client.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/config.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/defer.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/env.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/middleware.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/__init__.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/case_insensitive_dict.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/__init__.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/api_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/base_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/dynamodb_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/managed_sqs_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/scheduled_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/unmanaged_sqs_event.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/mock/mock_context.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/payload_encoder.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/py.typed +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/util.py +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/dependency_links.txt +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/entry_points.txt +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/requires.txt +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda_unstable.egg-info/top_level.txt +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/pyproject.toml +0 -0
- {async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/setup.cfg +0 -0
|
@@ -14,4 +14,4 @@ from .models.events.managed_sqs_event import ManagedSQSEvent as ManagedSQSEvent
|
|
|
14
14
|
from .models.events.scheduled_event import ScheduledEvent as ScheduledEvent
|
|
15
15
|
from .models.events.unmanaged_sqs_event import UnmanagedSQSEvent as UnmanagedSQSEvent
|
|
16
16
|
|
|
17
|
-
__version__ = "0.4.
|
|
17
|
+
__version__ = "0.4.9"
|
|
@@ -221,7 +221,10 @@ def invoke(
|
|
|
221
221
|
mock_context = MockLambdaContext(task.get_function_name())
|
|
222
222
|
if task.trigger_type == TaskTriggerType.UNMANAGED_SQS:
|
|
223
223
|
mock_event = MockSQSLambdaEvent(body or "")
|
|
224
|
-
elif task.trigger_type
|
|
224
|
+
elif task.trigger_type in [
|
|
225
|
+
TaskTriggerType.MANAGED_SQS,
|
|
226
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
227
|
+
]:
|
|
225
228
|
sqs_payload = json.dumps(
|
|
226
229
|
{
|
|
227
230
|
"source_task_id": None,
|
|
@@ -4,7 +4,14 @@ import logging
|
|
|
4
4
|
import re
|
|
5
5
|
import time
|
|
6
6
|
from datetime import datetime, timezone
|
|
7
|
-
from typing import
|
|
7
|
+
from typing import (
|
|
8
|
+
Any,
|
|
9
|
+
Callable,
|
|
10
|
+
Dict,
|
|
11
|
+
List,
|
|
12
|
+
Optional,
|
|
13
|
+
Type,
|
|
14
|
+
)
|
|
8
15
|
from uuid import uuid4
|
|
9
16
|
|
|
10
17
|
from . import env
|
|
@@ -15,6 +22,7 @@ from .middleware import MET, RT, MiddlewareFunction, MiddlewareRegistration
|
|
|
15
22
|
from .models.events.api_event import APIEvent
|
|
16
23
|
from .models.events.base_event import BaseEvent
|
|
17
24
|
from .models.events.dynamodb_event import DynamoDBEvent
|
|
25
|
+
from .models.events.managed_sqs_batch_event import ManagedSQSBatchEvent
|
|
18
26
|
from .models.events.managed_sqs_event import ManagedSQSEvent
|
|
19
27
|
from .models.events.scheduled_event import ScheduledEvent
|
|
20
28
|
from .models.events.unmanaged_sqs_event import UnmanagedSQSEvent
|
|
@@ -280,6 +288,22 @@ class AsyncLambdaController:
|
|
|
280
288
|
self.set_current_lane(lane=lane_index)
|
|
281
289
|
break
|
|
282
290
|
self.set_current_invocation_id(_event.invocation_id)
|
|
291
|
+
elif task.trigger_type == TaskTriggerType.MANAGED_SQS_BATCH:
|
|
292
|
+
_event = ManagedSQSBatchEvent(*args)
|
|
293
|
+
lane_count = task.get_lane_count()
|
|
294
|
+
if lane_count == 1:
|
|
295
|
+
self.set_current_lane(lane=0)
|
|
296
|
+
else:
|
|
297
|
+
assert all(
|
|
298
|
+
event.event_source_arn == _event.events[0].event_source_arn
|
|
299
|
+
for event in _event.events
|
|
300
|
+
)
|
|
301
|
+
for lane_index in range(lane_count):
|
|
302
|
+
if _event.events[0].event_source_arn == task.get_managed_queue_arn(
|
|
303
|
+
lane=lane_index
|
|
304
|
+
):
|
|
305
|
+
self.set_current_lane(lane=lane_index)
|
|
306
|
+
break
|
|
283
307
|
elif task.trigger_type == TaskTriggerType.UNMANAGED_SQS:
|
|
284
308
|
_event = UnmanagedSQSEvent(*args)
|
|
285
309
|
elif task.trigger_type == TaskTriggerType.SCHEDULED_EVENT:
|
|
@@ -307,7 +331,7 @@ class AsyncLambdaController:
|
|
|
307
331
|
self,
|
|
308
332
|
destination_task_id: str,
|
|
309
333
|
sqs_payload: dict,
|
|
310
|
-
delay:
|
|
334
|
+
delay: int = 0,
|
|
311
335
|
force_sync: bool = False,
|
|
312
336
|
lane: Optional[int] = None,
|
|
313
337
|
):
|
|
@@ -422,7 +446,7 @@ class AsyncLambdaController:
|
|
|
422
446
|
self,
|
|
423
447
|
task_id: str,
|
|
424
448
|
payload: Any,
|
|
425
|
-
delay:
|
|
449
|
+
delay: int = 0,
|
|
426
450
|
force_sync: bool = False,
|
|
427
451
|
lane: Optional[int] = None,
|
|
428
452
|
):
|
|
@@ -481,6 +505,52 @@ class AsyncLambdaController:
|
|
|
481
505
|
"is_dlq_task": is_dlq_task,
|
|
482
506
|
"lane_count": lane_count,
|
|
483
507
|
"propagate_lane_assignment": propagate_lane_assignment,
|
|
508
|
+
"batch_size": 1,
|
|
509
|
+
},
|
|
510
|
+
**kwargs,
|
|
511
|
+
)
|
|
512
|
+
)
|
|
513
|
+
return inner
|
|
514
|
+
|
|
515
|
+
return _task
|
|
516
|
+
|
|
517
|
+
def async_batch_task(
|
|
518
|
+
self,
|
|
519
|
+
task_id: str,
|
|
520
|
+
max_receive_count: int = 1,
|
|
521
|
+
dlq_task_id: Optional[str] = None,
|
|
522
|
+
is_dlq_task: bool = False,
|
|
523
|
+
lane_count: Optional[int] = None,
|
|
524
|
+
propagate_lane_assignment: Optional[bool] = None,
|
|
525
|
+
batch_size: int = 20,
|
|
526
|
+
**kwargs,
|
|
527
|
+
):
|
|
528
|
+
"""
|
|
529
|
+
Decorate a function to register it as an async batch task.
|
|
530
|
+
These functions can be asynchronously invoked with the `async_invoke` function
|
|
531
|
+
via their `task_id`.
|
|
532
|
+
"""
|
|
533
|
+
logger.debug(f"Registering async batch task '{task_id}' with the controller.")
|
|
534
|
+
|
|
535
|
+
def _task(func: Callable[[ManagedSQSBatchEvent], Any]):
|
|
536
|
+
@functools.wraps(func)
|
|
537
|
+
def inner(*args, **kwargs):
|
|
538
|
+
self.set_current_task_id(task_id)
|
|
539
|
+
return func(*args, **kwargs)
|
|
540
|
+
|
|
541
|
+
self.add_task(
|
|
542
|
+
AsyncLambdaTask(
|
|
543
|
+
controller=self,
|
|
544
|
+
executable=inner,
|
|
545
|
+
task_id=task_id,
|
|
546
|
+
trigger_type=TaskTriggerType.MANAGED_SQS_BATCH,
|
|
547
|
+
trigger_config={
|
|
548
|
+
"max_receive_count": max_receive_count,
|
|
549
|
+
"dlq_task_id": dlq_task_id,
|
|
550
|
+
"is_dlq_task": is_dlq_task,
|
|
551
|
+
"lane_count": lane_count,
|
|
552
|
+
"propagate_lane_assignment": propagate_lane_assignment,
|
|
553
|
+
"batch_size": batch_size,
|
|
484
554
|
},
|
|
485
555
|
**kwargs,
|
|
486
556
|
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from .base_event import BaseEvent
|
|
4
|
+
from .managed_sqs_event import ManagedSQSEvent
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ManagedSQSBatchEvent(BaseEvent):
|
|
8
|
+
events: List[ManagedSQSEvent]
|
|
9
|
+
|
|
10
|
+
def _hydrate_event(self):
|
|
11
|
+
self.events = []
|
|
12
|
+
for i in range(len(self._event["Records"])):
|
|
13
|
+
managed_sqs_event = ManagedSQSEvent(
|
|
14
|
+
{"Records": [self._event["Records"][i]]}, self._context, self._task
|
|
15
|
+
)
|
|
16
|
+
self.events.append(managed_sqs_event)
|
{async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/mock/mock_event.py
RENAMED
|
@@ -29,6 +29,36 @@ def MockSQSLambdaEvent(body: str, source_queue_arn: Optional[str] = None) -> dic
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
|
|
32
|
+
def MockSQSBatchLambdaEvent(
|
|
33
|
+
bodies: List[str], source_queue_arn: Optional[str] = None
|
|
34
|
+
) -> dict:
|
|
35
|
+
now_timestamp = int(time())
|
|
36
|
+
if not source_queue_arn:
|
|
37
|
+
source_queue_arn = "arn:aws:sqs:us-east-1:123456789012:my-queue"
|
|
38
|
+
|
|
39
|
+
records = []
|
|
40
|
+
for body in bodies:
|
|
41
|
+
records.append(
|
|
42
|
+
{
|
|
43
|
+
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7e",
|
|
44
|
+
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0b",
|
|
45
|
+
"body": body,
|
|
46
|
+
"attributes": {
|
|
47
|
+
"ApproximateReceiveCount": "1",
|
|
48
|
+
"SentTimestamp": str(now_timestamp),
|
|
49
|
+
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
|
|
50
|
+
"ApproximateFirstReceiveTimestamp": str(now_timestamp + 5),
|
|
51
|
+
},
|
|
52
|
+
"messageAttributes": {},
|
|
53
|
+
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b4",
|
|
54
|
+
"eventSource": "aws:sqs",
|
|
55
|
+
"eventSourceARN": source_queue_arn,
|
|
56
|
+
"awsRegion": "us-east-1",
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
return {"Records": records}
|
|
60
|
+
|
|
61
|
+
|
|
32
62
|
def MockAPILambdaEvent(
|
|
33
63
|
path: str,
|
|
34
64
|
method: str,
|
|
@@ -15,6 +15,7 @@ if TYPE_CHECKING:
|
|
|
15
15
|
|
|
16
16
|
from ..middleware import RT, MiddlewareStackExecutor
|
|
17
17
|
from .events.dynamodb_event import DynamoDBEvent
|
|
18
|
+
from .events.managed_sqs_batch_event import ManagedSQSBatchEvent
|
|
18
19
|
from .events.managed_sqs_event import ManagedSQSEvent
|
|
19
20
|
from .events.scheduled_event import ScheduledEvent
|
|
20
21
|
from .events.unmanaged_sqs_event import UnmanagedSQSEvent
|
|
@@ -22,15 +23,22 @@ from .events.unmanaged_sqs_event import UnmanagedSQSEvent
|
|
|
22
23
|
|
|
23
24
|
class TaskTriggerType(Enum):
|
|
24
25
|
MANAGED_SQS = 1
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
MANAGED_SQS_BATCH = 2
|
|
27
|
+
UNMANAGED_SQS = 3
|
|
28
|
+
SCHEDULED_EVENT = 4
|
|
29
|
+
API_EVENT = 5
|
|
30
|
+
DYNAMODB_EVENT = 6
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
EventType = TypeVar(
|
|
32
34
|
"EventType",
|
|
33
|
-
bound=Union[
|
|
35
|
+
bound=Union[
|
|
36
|
+
ManagedSQSEvent,
|
|
37
|
+
ManagedSQSBatchEvent,
|
|
38
|
+
ScheduledEvent,
|
|
39
|
+
UnmanagedSQSEvent,
|
|
40
|
+
DynamoDBEvent,
|
|
41
|
+
],
|
|
34
42
|
)
|
|
35
43
|
|
|
36
44
|
|
|
@@ -81,7 +89,8 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
81
89
|
self._has_run_init_tasks = False
|
|
82
90
|
|
|
83
91
|
if (
|
|
84
|
-
self.trigger_type
|
|
92
|
+
self.trigger_type
|
|
93
|
+
in [TaskTriggerType.MANAGED_SQS, TaskTriggerType.MANAGED_SQS_BATCH]
|
|
85
94
|
and "dlq_task_id" in self.trigger_config
|
|
86
95
|
):
|
|
87
96
|
dlq_task_id = self.trigger_config["dlq_task_id"]
|
|
@@ -91,7 +100,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
91
100
|
raise Exception(
|
|
92
101
|
f"Error setting DLQ Task ID: No task with the task_id {dlq_task_id} exists."
|
|
93
102
|
)
|
|
94
|
-
if dlq_task.trigger_type
|
|
103
|
+
if dlq_task.trigger_type not in [
|
|
104
|
+
TaskTriggerType.MANAGED_SQS,
|
|
105
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
106
|
+
]:
|
|
95
107
|
raise Exception(
|
|
96
108
|
f"Error setting DLQ Task ID: Task {dlq_task_id} is not an async-task."
|
|
97
109
|
)
|
|
@@ -119,7 +131,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
119
131
|
raise ValueError("Task ID must be less than 32 characters long.")
|
|
120
132
|
|
|
121
133
|
def get_lane_count(self) -> int:
|
|
122
|
-
if self.trigger_type
|
|
134
|
+
if self.trigger_type not in [
|
|
135
|
+
TaskTriggerType.MANAGED_SQS,
|
|
136
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
137
|
+
]:
|
|
123
138
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
124
139
|
if "lane_count" in self.trigger_config and isinstance(
|
|
125
140
|
self.trigger_config["lane_count"], int
|
|
@@ -128,7 +143,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
128
143
|
return self.controller.get_lane_count()
|
|
129
144
|
|
|
130
145
|
def should_propagate_lane_assignment(self) -> bool:
|
|
131
|
-
if self.trigger_type
|
|
146
|
+
if self.trigger_type not in [
|
|
147
|
+
TaskTriggerType.MANAGED_SQS,
|
|
148
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
149
|
+
]:
|
|
132
150
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
133
151
|
if "propagate_lane_assignment" in self.trigger_config and isinstance(
|
|
134
152
|
self.trigger_config["propagate_lane_assignment"], bool
|
|
@@ -140,7 +158,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
140
158
|
"""
|
|
141
159
|
Returns the managed queue's name for this task.
|
|
142
160
|
"""
|
|
143
|
-
if self.trigger_type
|
|
161
|
+
if self.trigger_type not in [
|
|
162
|
+
TaskTriggerType.MANAGED_SQS,
|
|
163
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
164
|
+
]:
|
|
144
165
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
145
166
|
if lane == 0:
|
|
146
167
|
return f"{config.name}-{self.task_id}"
|
|
@@ -150,12 +171,18 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
150
171
|
return f"{config.name}-{self.task_id}"
|
|
151
172
|
|
|
152
173
|
def get_managed_queue_arn(self, lane: int = 0):
|
|
153
|
-
if self.trigger_type
|
|
174
|
+
if self.trigger_type not in [
|
|
175
|
+
TaskTriggerType.MANAGED_SQS,
|
|
176
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
177
|
+
]:
|
|
154
178
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
155
179
|
return f"arn:aws:sqs:{env.get_aws_region()}:{env.get_aws_account_id()}:{self.get_managed_queue_name(lane=lane)}"
|
|
156
180
|
|
|
157
181
|
def get_managed_queue_url(self, lane: int = 0):
|
|
158
|
-
if self.trigger_type
|
|
182
|
+
if self.trigger_type not in [
|
|
183
|
+
TaskTriggerType.MANAGED_SQS,
|
|
184
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
185
|
+
]:
|
|
159
186
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
160
187
|
return f"https://sqs.{env.get_aws_region()}.amazonaws.com/{env.get_aws_account_id()}/{self.get_managed_queue_name(lane=lane)}"
|
|
161
188
|
|
|
@@ -163,21 +190,30 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
163
190
|
return f"{self.task_id}ALFunc"
|
|
164
191
|
|
|
165
192
|
def get_managed_queue_logical_id(self, lane: int = 0):
|
|
166
|
-
if self.trigger_type
|
|
193
|
+
if self.trigger_type not in [
|
|
194
|
+
TaskTriggerType.MANAGED_SQS,
|
|
195
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
196
|
+
]:
|
|
167
197
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
168
198
|
if lane == 0:
|
|
169
199
|
return f"{self.task_id}ALQueue"
|
|
170
200
|
return f"{self.task_id}ALQueueL{lane}"
|
|
171
201
|
|
|
172
202
|
def get_managed_queue_extra_logical_id(self, index: int, lane: int = 0):
|
|
173
|
-
if self.trigger_type
|
|
203
|
+
if self.trigger_type not in [
|
|
204
|
+
TaskTriggerType.MANAGED_SQS,
|
|
205
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
206
|
+
]:
|
|
174
207
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
175
208
|
if lane == 0:
|
|
176
209
|
return f"{self.get_function_logical_id()}Extra{index}"
|
|
177
210
|
return f"{self.get_function_logical_id()}Extra{index}L{lane}"
|
|
178
211
|
|
|
179
212
|
def get_managed_queue_event_logical_id(self, lane: int = 0):
|
|
180
|
-
if self.trigger_type
|
|
213
|
+
if self.trigger_type not in [
|
|
214
|
+
TaskTriggerType.MANAGED_SQS,
|
|
215
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
216
|
+
]:
|
|
181
217
|
raise Exception(f"The task {self.task_id} is not a managed queue task.")
|
|
182
218
|
if lane == 0:
|
|
183
219
|
return "ManagedSQS"
|
|
@@ -185,16 +221,17 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
185
221
|
|
|
186
222
|
def get_template_events(self) -> dict:
|
|
187
223
|
sqs_properties = {}
|
|
188
|
-
if (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
224
|
+
if isinstance(self.maximum_concurrency, list) and self.trigger_type not in [
|
|
225
|
+
TaskTriggerType.MANAGED_SQS,
|
|
226
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
227
|
+
]:
|
|
192
228
|
raise Exception(
|
|
193
229
|
f"Invalid maximum concurrency configuration for task {self.task_id}. Must be an int, not a list of ints. Lanes are only supported for ManagedSQS tasks."
|
|
194
230
|
)
|
|
195
231
|
if (
|
|
196
232
|
isinstance(self.maximum_concurrency, list)
|
|
197
|
-
and self.trigger_type
|
|
233
|
+
and self.trigger_type
|
|
234
|
+
in [TaskTriggerType.MANAGED_SQS, TaskTriggerType.MANAGED_SQS_BATCH]
|
|
198
235
|
and len(self.maximum_concurrency) != self.get_lane_count()
|
|
199
236
|
):
|
|
200
237
|
raise Exception(
|
|
@@ -204,7 +241,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
204
241
|
sqs_properties["ScalingConfig"] = {
|
|
205
242
|
"MaximumConcurrency": self.maximum_concurrency
|
|
206
243
|
}
|
|
207
|
-
if self.trigger_type
|
|
244
|
+
if self.trigger_type in [
|
|
245
|
+
TaskTriggerType.MANAGED_SQS,
|
|
246
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
247
|
+
]:
|
|
208
248
|
events = {}
|
|
209
249
|
for lane_index in range(self.get_lane_count()):
|
|
210
250
|
sqs_properties = {}
|
|
@@ -219,7 +259,7 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
219
259
|
events[self.get_managed_queue_event_logical_id(lane=lane_index)] = {
|
|
220
260
|
"Type": "SQS",
|
|
221
261
|
"Properties": {
|
|
222
|
-
"BatchSize":
|
|
262
|
+
"BatchSize": self.trigger_config["batch_size"],
|
|
223
263
|
"Enabled": True,
|
|
224
264
|
"Queue": {
|
|
225
265
|
"Fn::GetAtt": [
|
|
@@ -284,7 +324,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
284
324
|
raise NotImplementedError()
|
|
285
325
|
|
|
286
326
|
def get_policy_sqs_resources(self) -> List[dict]:
|
|
287
|
-
if self.trigger_type
|
|
327
|
+
if self.trigger_type in [
|
|
328
|
+
TaskTriggerType.MANAGED_SQS,
|
|
329
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
330
|
+
]:
|
|
288
331
|
return [
|
|
289
332
|
{
|
|
290
333
|
"Fn::GetAtt": [
|
|
@@ -332,7 +375,8 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
332
375
|
managed_tasks_resources = [
|
|
333
376
|
resource
|
|
334
377
|
for task in tasks
|
|
335
|
-
if task.trigger_type
|
|
378
|
+
if task.trigger_type
|
|
379
|
+
in [TaskTriggerType.MANAGED_SQS, TaskTriggerType.MANAGED_SQS_BATCH]
|
|
336
380
|
for resource in task.get_policy_sqs_resources()
|
|
337
381
|
]
|
|
338
382
|
if len(managed_tasks_resources) > 0:
|
|
@@ -408,7 +452,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
408
452
|
}
|
|
409
453
|
}
|
|
410
454
|
|
|
411
|
-
if self.trigger_type
|
|
455
|
+
if self.trigger_type in [
|
|
456
|
+
TaskTriggerType.MANAGED_SQS,
|
|
457
|
+
TaskTriggerType.MANAGED_SQS_BATCH,
|
|
458
|
+
]:
|
|
412
459
|
dlq_task = self.get_dlq_task()
|
|
413
460
|
if dlq_task is None:
|
|
414
461
|
dead_letter_target_arn = {
|
|
@@ -429,10 +476,7 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
429
476
|
"async-lambda-lane": str(lane_index),
|
|
430
477
|
"async-lambda-queue-type": "managed",
|
|
431
478
|
}
|
|
432
|
-
if
|
|
433
|
-
self.trigger_type == TaskTriggerType.MANAGED_SQS
|
|
434
|
-
and self.trigger_config["is_dlq_task"]
|
|
435
|
-
):
|
|
479
|
+
if self.trigger_config["is_dlq_task"]:
|
|
436
480
|
_extra_tags["async-lambda-queue-type"] = "dlq-task"
|
|
437
481
|
template[self.get_managed_queue_logical_id(lane=lane_index)] = {
|
|
438
482
|
"Type": "AWS::SQS::Queue",
|
|
@@ -474,7 +518,10 @@ class AsyncLambdaTask(Generic[EventType, RT]):
|
|
|
474
518
|
return json.loads(stringified_extra)
|
|
475
519
|
|
|
476
520
|
def get_dlq_task(self) -> Optional["AsyncLambdaTask"]:
|
|
477
|
-
if self.trigger_type
|
|
521
|
+
if self.trigger_type not in [
|
|
522
|
+
TaskTriggerType.MANAGED_SQS,
|
|
523
|
+
TaskTriggerType.MANAGED_SQS,
|
|
524
|
+
]:
|
|
478
525
|
return None
|
|
479
526
|
if self.trigger_config.get("is_dlq_task"):
|
|
480
527
|
return None
|
|
@@ -19,6 +19,7 @@ async_lambda/models/events/__init__.py
|
|
|
19
19
|
async_lambda/models/events/api_event.py
|
|
20
20
|
async_lambda/models/events/base_event.py
|
|
21
21
|
async_lambda/models/events/dynamodb_event.py
|
|
22
|
+
async_lambda/models/events/managed_sqs_batch_event.py
|
|
22
23
|
async_lambda/models/events/managed_sqs_event.py
|
|
23
24
|
async_lambda/models/events/scheduled_event.py
|
|
24
25
|
async_lambda/models/events/unmanaged_sqs_event.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/__init__.py
RENAMED
|
File without changes
|
{async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/api_event.py
RENAMED
|
File without changes
|
{async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/events/base_event.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{async-lambda-unstable-0.4.7 → async-lambda-unstable-0.4.9}/async_lambda/models/mock/mock_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|