forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
32 lines (26 loc) · 1.12 KB
/
functions.py
File metadata and controls
32 lines (26 loc) · 1.12 KB
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
import time
from concurrent.futures import Future, ThreadPoolExecutor
from typing import List
from tests.e2e.utils import data_fetcher # noqa F401
def execute_lambdas_in_parallel(function_name: str, lambdas_arn: list, arguments: str):
result_list = []
with ThreadPoolExecutor() as executor:
running_tasks: List[Future] = []
for arn in lambdas_arn:
# Sleep 0.5, 1, 1.5, ... seconds between each invocation. This way
# we can guarantee that lambdas are executed in parallel, but they are
# called in the same "order" as they are passed in, thus guaranteeing that
# we can assert on the correct output.
time.sleep(0.5 * len(running_tasks))
running_tasks.append(
executor.submit(
lambda lname, larn, largs: eval(lname)(larn, largs),
function_name,
arn,
arguments,
),
)
executor.shutdown(wait=True)
for running_task in running_tasks:
result_list.append(running_task.result())
return result_list