summaryrefslogtreecommitdiffstats
path: root/func/overlord/modules/utils.py
diff options
context:
space:
mode:
authorKrzysztof A. Adamski <krzysztofa@gmail.com>2008-08-07 19:05:58 -0400
committerKrzysztof A. Adamski <krzysztofa@gmail.com>2008-08-07 19:05:58 -0400
commitbb9dbf973f9bbc2024142e0f6e0b625a6d503803 (patch)
treea02578827699b9220a29916fa82e552a5eede591 /func/overlord/modules/utils.py
parent9c7f1053c9823e9c39df3233f56a04368002ef9d (diff)
downloadfunc-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.tar.gz
func-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.tar.xz
func-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.zip
Use polling method from overlord module in call cmd_module.
Diffstat (limited to 'func/overlord/modules/utils.py')
-rw-r--r--func/overlord/modules/utils.py37
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)