summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorKrzysztof A. Adamski <krzysztofa@gmail.com>2008-05-31 07:34:41 -0400
committerKrzysztof A. Adamski <krzysztofa@gmail.com>2008-05-31 07:34:41 -0400
commitea70b80d0378b21da53166f76e796692ecf20b33 (patch)
tree1711edac7f43b110624b55eda8ffabbc17c80f0b /func
parent3a66e1bfe011bc8ffc42ad8dcda672c76af8352d (diff)
downloadthird_party-func-ea70b80d0378b21da53166f76e796692ecf20b33.tar.gz
third_party-func-ea70b80d0378b21da53166f76e796692ecf20b33.tar.xz
third_party-func-ea70b80d0378b21da53166f76e796692ecf20b33.zip
Added --async option to 'call' cmd_module.
Diffstat (limited to 'func')
-rw-r--r--func/overlord/base_command.py3
-rw-r--r--func/overlord/cmd_modules/call.py37
2 files changed, 39 insertions, 1 deletions
diff --git a/func/overlord/base_command.py b/func/overlord/base_command.py
index d2f9a9f..bacb005 100644
--- a/func/overlord/base_command.py
+++ b/func/overlord/base_command.py
@@ -28,4 +28,5 @@ class BaseCommand(command.Command):
port=self.port,
interactive=self.interactive,
verbose=self.verbose,
- config=self.config)
+ config=self.config,
+ async=self.options.async)
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