diff options
Diffstat (limited to 'func/overlord/modules/utils.py')
-rw-r--r-- | func/overlord/modules/utils.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/func/overlord/modules/utils.py b/func/overlord/modules/utils.py new file mode 100644 index 0000000..1e074a1 --- /dev/null +++ b/func/overlord/modules/utils.py @@ -0,0 +1,37 @@ +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) |