summaryrefslogtreecommitdiffstats
path: root/func/overlord/modules/utils.py
blob: f18fd50db839dfdad48742c88704edd78c11d0f0 (plain)
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
import time

from func.overlord import overlord_module
import func.jobthing as jobthing

class utils(overlord_module.BaseModule):
    def __diff_dicts(self, a, b):
        return dict([(k, v) for k, v in a.iteritems() if k not in b])
        

    def async_poll(self, job_id, partial_func=None, interval=0.5):
        async_done = False
        partial = {}
        while not async_done:
            (return_code, async_results) = self.parent.job_status(job_id)
            if return_code == jobthing.JOB_ID_RUNNING:
                pass
            elif return_code == jobthing.JOB_ID_FINISHED:
                async_done = True
                if partial_func:
                    diff = self.__diff_dicts(async_results, partial)
                    if len(diff) > 0:
                        partial_func(diff)
                return async_results
            elif return_code == jobthing.JOB_ID_PARTIAL:
                pass
                if partial_func:
                    diff = self.__diff_dicts(async_results, partial)
                    if len(diff) > 0:
                        partial_func(diff)
                        partial=async_results
            else:
                #FIXME -- raise exception instead of printing
                print "Async error", return_code, async_results
                return 0

            time.sleep(interval)

    def list_minions(self):
       return self.parent.minions