-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.py
75 lines (63 loc) · 1.75 KB
/
job.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
63
64
65
66
67
68
69
70
71
72
73
74
# job.py
# Simple job to demonstrate posdo operation
# Worker sleeps for a second and then prints it performed a task
i = 0
def job_init(args):
"""
Initialize the job.
Returns 0 on success.
"""
global i
i = 0
posdo.info('running with %d uvs' % (posdo.uvs_nof()))
return 0
#def job_get_options(): return ...
def job_get_globals():
"""
Get job globals to be used on all UVs.
Return empty string to signify no globals.
"""
return ''
def job_get_status():
""" Obtain job status (optional).
Returns:
0, 0 - job complete
1, N - job not complete, require N more results before job_get_arg() can be called
"""
global i
if i == 10: return 0, 0
return 1, 0
def job_get_arg(task_num):
"""
Get a job argument/task to be executed on a UV.
Returns None to signify no more arguments/tasks are left
and that this job is done (optional if job_get_status() is defined).
"""
global i
if i == 10: return None # return None to signal the end of the job
arg = str(i)
i = i + 1
return arg
def job_add_result(task_num, result):
"""
Process a result of an executed argument/task
"""
posdo.info(result)
def job_notify_failure(task_num):
"""
Process an argument/task execution failure (optional)
"""
pass
def job_finish():
"""
Called when all job processing is complete.
"""
posdo.info('job completed')
# Posdo will remote job_worker() and below to UV
def job_worker(arg):
return 'internally ' + job_internal_call(arg)
def job_internal_call(arg):
import time
time.sleep(1)
result = 'performed task %s' % (arg)
return result