forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_progress.py
49 lines (42 loc) · 1.12 KB
/
test_progress.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
from dflow import (
Workflow,
Step
)
from dflow.python import (
PythonOPTemplate,
OP,
OPIO,
OPIOSign
)
import time
class Progress(OP):
progress_total = 100
@classmethod
def get_input_sign(cls):
return OPIOSign()
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in: OPIO,
) -> OPIO:
for i in range(10):
time.sleep(10)
self.progress_current = 10 * (i + 1)
return OPIO()
if __name__ == "__main__":
wf = Workflow(name="progress")
step = Step(name="step", template=PythonOPTemplate(Progress, image="dptechnology/dflow"))
# This step will report progress every 10 seconds
wf.add(step)
wf.submit()
while wf.query_status() in ["Pending", "Running"]:
time.sleep(1)
step = wf.query_step(name="step")
if len(step) > 0 and hasattr(step[0], "progress"):
print(step[0].progress)
assert(wf.query_status() == "Succeeded")
step = wf.query_step(name="step")[0]
assert(step.progress == "100/100")