mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-14 20:29:11 -07:00
Update async_wrapper.py to remove own temp dir. (#5719)
This commit is contained in:
parent
d41b4e3802
commit
86d53db3e4
1 changed files with 15 additions and 2 deletions
|
@ -24,6 +24,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
import shlex
|
import shlex
|
||||||
|
import shutil
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
@ -204,7 +205,8 @@ if __name__ == '__main__':
|
||||||
if len(sys.argv) < 5:
|
if len(sys.argv) < 5:
|
||||||
print(json.dumps({
|
print(json.dumps({
|
||||||
"failed" : True,
|
"failed" : True,
|
||||||
"msg" : "usage: async_wrapper <jid> <time_limit> <modulescript> <argsfile>. Humans, do not call directly!"
|
"msg" : "usage: async_wrapper <jid> <time_limit> <modulescript> <argsfile> [-preserve_tmp] "
|
||||||
|
"Humans, do not call directly!"
|
||||||
}))
|
}))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -212,6 +214,12 @@ if __name__ == '__main__':
|
||||||
time_limit = sys.argv[2]
|
time_limit = sys.argv[2]
|
||||||
wrapped_module = sys.argv[3]
|
wrapped_module = sys.argv[3]
|
||||||
argsfile = sys.argv[4]
|
argsfile = sys.argv[4]
|
||||||
|
if '-tmp-' not in os.path.dirname(wrapped_module):
|
||||||
|
preserve_tmp = True
|
||||||
|
elif len(sys.argv) > 5:
|
||||||
|
preserve_tmp = sys.argv[5] == '-preserve_tmp'
|
||||||
|
else:
|
||||||
|
preserve_tmp = False
|
||||||
# consider underscore as no argsfile so we can support passing of additional positional parameters
|
# consider underscore as no argsfile so we can support passing of additional positional parameters
|
||||||
if argsfile != '_':
|
if argsfile != '_':
|
||||||
cmd = "%s %s" % (wrapped_module, argsfile)
|
cmd = "%s %s" % (wrapped_module, argsfile)
|
||||||
|
@ -244,7 +252,8 @@ if __name__ == '__main__':
|
||||||
# this probably could be done with some IPC later. Modules should always read
|
# this probably could be done with some IPC later. Modules should always read
|
||||||
# the argsfile at the very first start of their execution anyway
|
# the argsfile at the very first start of their execution anyway
|
||||||
notice("Return async_wrapper task started.")
|
notice("Return async_wrapper task started.")
|
||||||
print(json.dumps({ "started" : 1, "finished" : 0, "ansible_job_id" : jid, "results_file" : job_path }))
|
print(json.dumps({ "started" : 1, "finished" : 0, "ansible_job_id" : jid, "results_file" : job_path,
|
||||||
|
"_suppress_tmpdir_delete": not preserve_tmp}))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -276,8 +285,12 @@ if __name__ == '__main__':
|
||||||
os.killpg(sub_pid, signal.SIGKILL)
|
os.killpg(sub_pid, signal.SIGKILL)
|
||||||
notice("Sent kill to group %s"%sub_pid)
|
notice("Sent kill to group %s"%sub_pid)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
if not preserve_tmp:
|
||||||
|
shutil.rmtree(os.path.dirname(wrapped_module), True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
notice("Done in kid B.")
|
notice("Done in kid B.")
|
||||||
|
if not preserve_tmp:
|
||||||
|
shutil.rmtree(os.path.dirname(wrapped_module), True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
# the child process runs the actual module
|
# the child process runs the actual module
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue