async module now forks

reviewable/pr18780/r1
Michael DeHaan 13 years ago
parent 7f272d8b25
commit 6632bef17d

@ -36,9 +36,11 @@ if len(sys.argv) < 3:
}) })
sys.exit(1) sys.exit(1)
print sys.argv
jid = sys.argv[1] jid = sys.argv[1]
wrapped_module = sys.argv[2] time_limit = sys.argv[2]
time_limit = sys.argv[3] wrapped_module = sys.argv[3]
args = sys.argv[4:] args = sys.argv[4:]
cmd = "%s %s" % (wrapped_module, " ".join(args)) cmd = "%s %s" % (wrapped_module, " ".join(args))
@ -73,11 +75,13 @@ def _run_command(wrapped_cmd, jid, log_path):
except (OSError, IOError), e: except (OSError, IOError), e:
result = { result = {
"failed": 1, "failed": 1,
"cmd" : wrapped_cmd,
"msg": str(e), "msg": str(e),
} }
except: except:
result = { result = {
"failed" : 1, "failed" : 1,
"cmd" : wrapped_cmd,
"msg" : traceback.format_exc() "msg" : traceback.format_exc()
} }
@ -86,12 +90,28 @@ def _run_command(wrapped_cmd, jid, log_path):
logfile.write(json.dumps(result)) logfile.write(json.dumps(result))
logfile.close() logfile.close()
# TEMPORARY:
print json.dumps(result)
# TODO: daemonize this with time limits # TODO: daemonize this with time limits
# TODO: might be nice to keep timing data, eventually... # TODO: might be nice to keep timing data, eventually...
_run_command(cmd, jid, log_path)
pid = os.fork()
if pid == 0:
print json.dumps({ "started" : 1, "ansible_job_id" : jid })
sys.exit(0)
else:
# FIXME: need to implement time limits
# probably something easy like:
#
# sub_pid = os.fork()
# if sub_pid == 0:
# run command
# else
# check status
# sleep 1 second
# kill if greater than timelimit
_run_command(cmd, jid, log_path)
sys.exit(0)

Loading…
Cancel
Save