From 74ef2b7e15a644828fcb627ae02b4a6c693c4829 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Tue, 1 Oct 2024 12:08:57 +0200 Subject: [PATCH] refs #789 run only one concurrent job --- src/opengnsys/modules/server/CloningEngine/__init__.py | 9 +++++++++ src/opengnsys/workers/oglive_worker.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/opengnsys/modules/server/CloningEngine/__init__.py b/src/opengnsys/modules/server/CloningEngine/__init__.py index 4e43ef4..a7c44cb 100644 --- a/src/opengnsys/modules/server/CloningEngine/__init__.py +++ b/src/opengnsys/modules/server/CloningEngine/__init__.py @@ -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), diff --git a/src/opengnsys/workers/oglive_worker.py b/src/opengnsys/workers/oglive_worker.py index 737c763..e09b74e 100644 --- a/src/opengnsys/workers/oglive_worker.py +++ b/src/opengnsys/workers/oglive_worker.py @@ -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