From f888d1da61b65380b649f24948edea419fca2f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Thu, 9 Jan 2020 11:10:10 +0100 Subject: [PATCH] Improvements * Added taskmanager foreground exec method * catch checkState exceptions (not expected anyway) and mark pubs as errored --- server/src/uds/core/managers/publication.py | 5 ++++- server/src/uds/core/managers/task.py | 1 + .../src/uds/management/commands/taskManager.py | 18 ++++++++++++++---- .../src/uds/models/service_pool_publication.py | 1 - 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/server/src/uds/core/managers/publication.py b/server/src/uds/core/managers/publication.py index 405bc46d..722c0c2a 100644 --- a/server/src/uds/core/managers/publication.py +++ b/server/src/uds/core/managers/publication.py @@ -192,7 +192,10 @@ class PublicationFinishChecker(DelayedTask): else: publicationInstance = publication.getInstance() logger.debug("publication instance class: %s", publicationInstance.__class__) - state = publicationInstance.checkState() + try: + state = publicationInstance.checkState() + except Exception: + state = State.ERROR PublicationFinishChecker.checkAndUpdateState(publication, publicationInstance, state) except Exception as e: logger.debug('Deployed service not found (erased from database) %s : %s', e.__class__, e) diff --git a/server/src/uds/core/managers/task.py b/server/src/uds/core/managers/task.py index a6c2da64..2fcca433 100644 --- a/server/src/uds/core/managers/task.py +++ b/server/src/uds/core/managers/task.py @@ -127,6 +127,7 @@ class TaskManager: time.sleep(0.5) # Wait a bit before next delayed task runner is started signal.signal(signal.SIGTERM, TaskManager.sigTerm) + signal.signal(signal.SIGINT, TaskManager.sigTerm) # Debugging stuff # import guppy diff --git a/server/src/uds/management/commands/taskManager.py b/server/src/uds/management/commands/taskManager.py index 420ae932..6ede3c03 100644 --- a/server/src/uds/management/commands/taskManager.py +++ b/server/src/uds/management/commands/taskManager.py @@ -102,6 +102,13 @@ class Command(BaseCommand): default=False, help='Stop any running daemon' ) + parser.add_argument( + '--foreground', + action='store_true', + dest='foreground', + default=False, + help='Stop any running daemon' + ) def handle(self, *args, **options) -> None: logger.info("Running task manager command") @@ -110,8 +117,9 @@ class Command(BaseCommand): start = options.get('start', False) stop = options.get('stop', False) + foreground = options.get('foreground', False) - logger.debug('Start: %s, Stop: %s', start, stop) + logger.debug('Start: %s, Stop: %s, Foreground: %s', start, stop, foreground) pid: int = 0 try: @@ -131,10 +139,12 @@ class Command(BaseCommand): if start: logger.info('Starting task manager.') - become_daemon(settings.BASE_DIR, settings.LOGDIR + '/taskManagerStdout.log', settings.LOGDIR + '/taskManagerStderr.log') - pid = str(os.getpid()) - open(getPidFile(), 'w+').write('{}\n'.format(pid)) + if not foreground: + become_daemon(settings.BASE_DIR, settings.LOGDIR + '/taskManagerStdout.log', settings.LOGDIR + '/taskManagerStderr.log') + pid = os.getpid() + + open(getPidFile(), 'w+').write('{}\n'.format(pid)) manager = taskManager()() manager.run() diff --git a/server/src/uds/models/service_pool_publication.py b/server/src/uds/models/service_pool_publication.py index d99275dd..30781bad 100644 --- a/server/src/uds/models/service_pool_publication.py +++ b/server/src/uds/models/service_pool_publication.py @@ -72,7 +72,6 @@ class ServicePoolPublication(UUIDModel): """ A deployed service publication keep track of data needed by services that needs "preparation". (i.e. Virtual machine --> base machine --> children of base machines) """ - # pylint: disable=model-missing-unicode deployed_service: ServicePool = models.ForeignKey(ServicePool, on_delete=models.CASCADE, related_name='publications') publish_date = models.DateTimeField(db_index=True) # data_type = models.CharField(max_length=128) # The data type is specified by the service itself