File: vine_python_serverless_failure.py

package info (click to toggle)
cctools 1%3A7.15.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,008 kB
  • sloc: ansic: 117,215; python: 30,569; cpp: 20,301; sh: 13,834; perl: 4,056; xml: 3,688; makefile: 1,502
file content (56 lines) | stat: -rwxr-xr-x 1,878 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3

# This test exercises the (rather complex) coupled failure mode
# of libraries and tasks together.  If a user submits a library
# with a bunch of function calls, but the library keeps crashing,
# then the following should eventually occur:

# 1 - The library template will be removed, and no more library
#     instances will be deployed.
# 2 - The function calls depending on that library should return
#     to the user with error LIBRARY_MISSING.

import ndcctools.taskvine as vine
import argparse
import os
import sys

def func( x ) :
    sys.exit(127)
    return x*x

def main():
    parser = argparse.ArgumentParser("Test for taskvine python serverless failure.")
    parser.add_argument("port_file", help="File to write the port the queue is using.")

    args = parser.parse_args()

    q = vine.Manager(port=0)
    q.tune("watch-library-logfiles", 1)  # get logs back from failed libraries
    q.tune("transient-error-interval",2) # retry failed libraries quickly
    q.tune("max-library-retries", 2)     # retry failed libraries only twice
    print(f"TaskVine manager listening on port {q.port}")

    with open(args.port_file, "w") as f:
        print("Writing port {port} to file {file}".format(port=q.port, file=args.port_file))
        f.write(str(q.port))

    print("Creating library from packages and functions...")
    libtask = q.create_library_from_functions("bad-library",func,add_env=False,exec_mode="direct")
    q.install_library(libtask)

    print("Submitting function call tasks...")
    for n in range(0,10):
        task = vine.FunctionCall("bad-library","func",n)
        q.submit(task)

    while not q.empty():
        t = q.wait(5)
        if t:
            print(f"task {t.id} completed with result {t.result} output {t.output}")

if __name__ == '__main__':
    main()


# vim: set sts=4 sw=4 ts=4 expandtab ft=python: