-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
worker.py
62 lines (56 loc) · 1.64 KB
/
worker.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import subprocess
import sys
# Checks to make sure that collections are loaded prior to attempting to start a worker
def main():
subprocess.check_call(
["python", "-m", "pip", "install", "prefect-kubernetes>=0.5.0"],
stdout=sys.stdout,
stderr=sys.stderr,
)
try:
subprocess.check_output(
["prefect", "work-pool", "delete", "test-pool"],
)
except subprocess.CalledProcessError:
pass
try:
subprocess.check_output(
["prefect", "work-pool", "create", "test-pool", "-t", "nonsense"],
)
except subprocess.CalledProcessError as e:
# Check that the error message contains kubernetes worker type
for type in ["process", "kubernetes"]:
assert type in str(
e.output
), f"Worker type {type!r} missing from output {e.output}"
subprocess.check_call(
["prefect", "work-pool", "create", "test-pool", "-t", "kubernetes"],
stdout=sys.stdout,
stderr=sys.stderr,
)
subprocess.check_call(
[
"prefect",
"worker",
"start",
"-p",
"test-pool",
"-t",
"kubernetes",
"--run-once",
],
stdout=sys.stdout,
stderr=sys.stderr,
)
subprocess.check_call(
["python", "-m", "pip", "uninstall", "prefect-kubernetes", "-y"],
stdout=sys.stdout,
stderr=sys.stderr,
)
subprocess.check_call(
["prefect", "work-pool", "delete", "test-pool"],
stdout=sys.stdout,
stderr=sys.stderr,
)
if __name__ == "__main__":
main()