-
Notifications
You must be signed in to change notification settings - Fork 7
/
test-vine-serverless.py
executable file
·47 lines (36 loc) · 1.22 KB
/
test-vine-serverless.py
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
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import ndcctools.taskvine as vine
import json
import sys
def divide(dividend, divisor):
import math
return dividend/math.sqrt(divisor)
def double(x):
return x*2
def main():
print("Creating TaskVine manager...")
q = vine.Manager(port=0)
print("Creating Library from functions...")
function_lib = q.create_library_from_functions('test-library', divide, double, add_env=False)
q.install_library(function_lib)
print("Starting worker factory for port {}...".format(q.port))
factory = vine.Factory("local",manager_host_port="localhost:{}".format(q.port))
factory.max_workers=1
factory.min_workers=1
with factory:
print("Submitting tasks...")
s_task = vine.FunctionCall('test-library', 'divide', 2, 2**2)
q.submit(s_task)
s_task = vine.FunctionCall('test-library', 'double', 3)
q.submit(s_task)
total_sum = 0
x = 0
print("Waiting for tasks to complete...")
while not q.empty():
t = q.wait(5)
if t:
x = t.output
total_sum += x
assert total_sum == divide(2, 2**2) + double(3)
if __name__ == '__main__':
main()