1
2 """
3 Support for job pools.
4
5 Example
6 =======
7
8 Using the above, you can set up a workflow which halts when any job on the
9 workflow improves past a certain point::
10
11 from park.core.pool import terminate, any_improved
12
13 M = mymodel
14 servers = ['compufans','teragrid','teragrid',local_service]
15 pool = [fit(M, server=s) for s in servers]
16 terminate(pool, when=any_improved(pool, 'chisq<20'), server=local_server)
17
18 TODO: How do we make the output of terminate be the result of the first
19 job to
20
21 :group Composite conditions:
22 any_improved, all_improved, any_completed, all_completed
23
24 :group Services:
25 terminate
26 """
27
28 __all__ = ['terminate', 'any_improved', 'all_improved',
29 'any_completed', 'all_completed']
30 import park.core.service as service
31
33 version='1.0'
36 - def run(self, handler):
37 for job in jobs:
38
39 handler.send(message.Abort(),
40 server=job['server'],
41 auth=job['auth'],
42 stream=job['stream'])
43 return []
44
46 """
47 Terminate a pool of jobs when condition is satisfied.
48 Standard job submission keywords are accepted, including::
49 when=condition
50 service=service
51 See `park.core.service.Proxy.submit`
52 """
53 jobs = [dict(stream=job.id,auth=job.auth,server=job.server)
54 for job in pool]
55 request = service.request(TerminateService, jobs=jobs)
56 job = service.Proxy()
57 job.submit(request=request, **kw)
58 return job
59
60
70
72 """
73 Condition is satisfied when any of a set of jobs are completed.
74 """
75 assert len(jobs)>0
76 condition = jobs[0].iscompleted()
77 for job in jobs[1:]:
78 condition |= job.iscompleted()
79
89
91 """
92 Condition is satisfied when any of a set of jobs are completed.
93 """
94 assert len(jobs)>0
95 condition = jobs[0].iscompleted()
96 for job in jobs[1:]:
97 condition &= job.iscompleted()
98