mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #27682 from rallytime/bp-27566
Back-port #27566 to 2015.5
This commit is contained in:
commit
a0f3e34656
1 changed files with 10 additions and 9 deletions
|
@ -103,30 +103,31 @@ def _format_jid_instance(jid, job):
|
|||
#TODO: add to returner docs-- this is a new one
|
||||
def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
|
||||
'''
|
||||
Return a job id and prepare the job id directory
|
||||
This is the function responsible for making sure jids don't collide (unless its passed a jid)
|
||||
Return a job id and prepare the job id directory.
|
||||
|
||||
This is the function responsible for making sure jids don't collide (unless
|
||||
it is passed a jid).
|
||||
So do what you have to do to make sure that stays the case
|
||||
'''
|
||||
if recurse_count >= 5:
|
||||
err = 'prep_jid could not store a jid after {0} tries.'.format(recurse_count)
|
||||
log.error(err)
|
||||
raise salt.exceptions.SaltCacheError(err)
|
||||
if passed_jid is None: # this can be a None of an empty string
|
||||
if passed_jid is None: # this can be a None or an empty string.
|
||||
jid = salt.utils.jid.gen_jid()
|
||||
else:
|
||||
jid = passed_jid
|
||||
|
||||
jid_dir_ = _jid_dir(jid)
|
||||
|
||||
# make sure we create the jid dir, otherwise someone else is using it,
|
||||
# meaning we need a new jid
|
||||
# Make sure we create the jid dir, otherwise someone else is using it,
|
||||
# meaning we need a new jid.
|
||||
try:
|
||||
os.makedirs(jid_dir_)
|
||||
except OSError:
|
||||
time.sleep(0.1)
|
||||
if passed_jid is None:
|
||||
recurse_count += recurse_count
|
||||
return prep_jid(nocache=nocache)
|
||||
return prep_jid(nocache=nocache, recurse_count=recurse_count+1)
|
||||
|
||||
try:
|
||||
with salt.utils.fopen(os.path.join(jid_dir_, 'jid'), 'wb+') as fn_:
|
||||
|
@ -137,8 +138,8 @@ def prep_jid(nocache=False, passed_jid=None, recurse_count=0):
|
|||
except IOError:
|
||||
log.warn('Could not write out jid file for job {0}. Retrying.'.format(jid))
|
||||
time.sleep(0.1)
|
||||
recurse_count += recurse_count
|
||||
return prep_jid(passed_jid=jid, nocache=nocache)
|
||||
return prep_jid(passed_jid=jid, nocache=nocache,
|
||||
recurse_count=recurse_count+1)
|
||||
|
||||
return jid
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue