Skip to content

Commit

Permalink
write the name to the queue state file only if it doesn't exist and n…
Browse files Browse the repository at this point in the history
…o-one else is writing it.
  • Loading branch information
petersilva committed Jan 30, 2024
1 parent aa0b6bf commit 288b994
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions sarracenia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,9 +1727,6 @@ def _resolveQueueName(self,component,cfg):
# only lead instance (0-foreground, 1-start, or none in the case of 'declare')
# should write the state file.

# first make sure directory exists.
if not os.path.isdir(os.path.dirname(queuefile)):
pathlib.Path(os.path.dirname(queuefile)).mkdir(parents=True, exist_ok=True)

# lead instance shou
if os.path.isfile(queuefile):
Expand All @@ -1750,10 +1747,21 @@ def _resolveQueueName(self,component,cfg):
if self.action not in [ 'start', 'foreground', 'declare' ]:
return

if (self.queueName is not None) and (not hasattr(self,'no') or (self.no < 2)):
f = open(queuefile, 'w')
f.write(self.queueName)
f.close()
# first make sure directory exists.
if not os.path.isdir(os.path.dirname(queuefile)):
pathlib.Path(os.path.dirname(queuefile)).mkdir(parents=True, exist_ok=True)

if not os.path.isfile(queuefile) and (self.queueName is not None):
tmpQfile=queuefile+'.tmp'
if not os.path.isfile(tmpQfile):
f = open(tmpQfile, 'w')
f.write(self.queueName)
f.close()
os.rename( tmpQfile, queuefile )
else:
logger.info( f'Queue name {self.queueName} being persisted to {queuefile} by some other process, so ignoring it.' )
return

logger.debug( f'queue name {self.queueName} persisted to {queuefile}' )


Expand Down

0 comments on commit 288b994

Please sign in to comment.