diff options
author | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-07 19:05:58 -0400 |
---|---|---|
committer | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-07 19:05:58 -0400 |
commit | bb9dbf973f9bbc2024142e0f6e0b625a6d503803 (patch) | |
tree | a02578827699b9220a29916fa82e552a5eede591 /func | |
parent | 9c7f1053c9823e9c39df3233f56a04368002ef9d (diff) | |
download | func-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.tar.gz func-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.tar.xz func-bb9dbf973f9bbc2024142e0f6e0b625a6d503803.zip |
Use polling method from overlord module in call cmd_module.
Diffstat (limited to 'func')
-rw-r--r-- | func/overlord/cmd_modules/call.py | 32 | ||||
-rw-r--r-- | func/overlord/modules/utils.py | 37 |
2 files changed, 42 insertions, 27 deletions
diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py index b58ee7c..0743442 100644 --- a/func/overlord/cmd_modules/call.py +++ b/func/overlord/cmd_modules/call.py @@ -16,7 +16,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import optparse import pprint import xmlrpclib -import time import sys from func.overlord import client @@ -156,26 +155,12 @@ class Call(base_command.BaseCommand): return async_results if self.options.async: - partial = {} + self.partial = {} if self.options.nopoll: print "JOB_ID:", pprint.pformat(results) return results else: - async_done = False - while not async_done: - (return_code, async_results) = self.overlord_obj.job_status(results) - if return_code == jobthing.JOB_ID_RUNNING: - time.sleep(0.1) - elif return_code == jobthing.JOB_ID_FINISHED: - async_done = True - partial = self.print_partial_results(partial, async_results, self.options.sort) - return partial - elif return_code == jobthing.JOB_ID_PARTIAL: - if not self.options.sort: - partial = self.print_partial_results(partial, async_results) - else: - sys.stderr.write("Async error") - return 0 + return self.overlord_obj.local.utils.async_poll(results, self.print_results) # dump the return code stuff atm till we figure out the right place for it foo = self.format_return(results) @@ -184,13 +169,6 @@ class Call(base_command.BaseCommand): # nothing really makes use of this atm -akl return results - def print_partial_results(self, old, new, sort=0): - diff = dict([(k, v) for k, v in new.iteritems() if k not in old]) - if len(diff) > 0: - iter=diff.iteritems() - if sort: - iter=sorted(iter) - for res in iter: - print self.format_return(res) - return new - return old + def print_results(self, res): + for i in res.iteritems(): + print self.format_return(i) 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) |