diff options
Diffstat (limited to 'func/overlord/cmd_modules/call.py')
-rw-r--r-- | func/overlord/cmd_modules/call.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py index 5ad1f26..5441ef8 100644 --- a/func/overlord/cmd_modules/call.py +++ b/func/overlord/cmd_modules/call.py @@ -16,10 +16,13 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import optparse import pprint import xmlrpclib +import time from func.overlord import client from func.overlord import base_command +import func.jobthing as jobthing + DEFAULT_FORKS = 1 class Call(base_command.BaseCommand): @@ -43,6 +46,12 @@ class Call(base_command.BaseCommand): self.parser.add_option("-f", "--forks", dest="forks", help="how many parallel processes? (default 1)", default=DEFAULT_FORKS) + self.parser.add_option("-a", "--async", dest="async", + help="Use async calls? (default 0)", + action="store_true") + self.parser.add_option("-n", "--nopoll", dest="nopoll", + help="Don't wait for async results", + action="store_true") def handleOptions(self, options): self.options = options @@ -114,6 +123,26 @@ class Call(base_command.BaseCommand): results = self.overlord_obj.run(self.module, self.method, self.method_args) + if self.options.async: + partial = {} + if self.options.nopoll: + print "JOB_ID", 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_ASYNC_FINISHED: + async_done = True + partial = self.print_partial_results(partial, async_results) + return 0 + elif return_code == jobthing.JOB_ID_ASYNC_PARTIAL: + partial = self.print_partial_results(partial, async_results) + else: + sys.stderr.write("Async error") + return 0 + # TO DO: add multiplexer support # probably as a higher level module. @@ -123,3 +152,11 @@ class Call(base_command.BaseCommand): # nothing really makes use of this atm -akl return foo + + def print_partial_results(self, old, new): + diff = dict([(k, v) for k, v in new.iteritems() if k not in old]) + if len(diff) > 0: + for res in diff.iteritems(): + print "2:",self.format_return(res) + return new + return old |