refs #789 run only one concurrent job

pull/9/head
Natalia Serrano 2024-10-01 12:08:57 +02:00
parent 9b91eedf1b
commit 74ef2b7e15
2 changed files with 10 additions and 1 deletions

View File

@ -187,6 +187,15 @@ class CloningEngineWorker (ogLiveWorker):
return self.respuestaEjecucionComando (cmd, herror, ids)
def _long_running_job (self, name, f, args):
any_job_running = False
for k in self.thread_list:
if self.thread_list[k]['running']:
any_job_running = True
break
if any_job_running:
logger.info ('some job is already running, refusing to launch another one')
return { 'job_id': None, 'message': 'some job is already running, refusing to launch another one' }
job_id = '{}-{}'.format (name, ''.join (random.choice ('0123456789abcdef') for _ in range (8)))
self.thread_list[job_id] = {
'thread': ThreadWithResult (target=f, args=args),

View File

@ -48,7 +48,7 @@ class ThreadWithResult (threading.Thread):
try:
self.result = self._target (*self._args, **self._kwargs)
except Exception as e:
self.result = f'got exception: ({e})'
self.result = { 'res': 2, 'der': f'got exception: ({e})' } ## res=2 as defined in ogAdmClient.c:2048
finally:
# Avoid a refcycle if the thread is running a function with an argument that has a member that points to the thread.
del self._target, self._args, self._kwargs