From d5b0a92a5bc21c8dbc77f36c11ad3c37ca826f9f Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 12 Jul 2017 15:58:18 +1000 Subject: [PATCH] MCPClient error check Gearman worker creation This patch adds a try/except block to the MCPClient when creating a Gearman worker in startThread(). Without this patch, if the MCPClient configuration item "MCPArchivematicaServer" has an invalid value, no Gearman worker will be created and Archivematica will be stuck thinking that a job is executing indefinitely with no indication of what happened in the user interface or the logs. To test, open "/etc/archivematica/MCPClient/clientConfig.conf", and change "MCPArchivematicaServer" to something invalid like "buffalo" or "localhost::9999", and then try to do a standard transfer in the Archivematica dashboard UI. In the micro-service "Verify transfer compliance", you'll get stuck at "Job: Set file permissions". It will say it's still executing but the job will never actually run. --- src/MCPClient/lib/archivematicaClient.py | 39 +++++++++++++----------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/MCPClient/lib/archivematicaClient.py b/src/MCPClient/lib/archivematicaClient.py index 8d95d8cea3..5148392d01 100755 --- a/src/MCPClient/lib/archivematicaClient.py +++ b/src/MCPClient/lib/archivematicaClient.py @@ -146,24 +146,27 @@ def executeCommand(gearman_worker, gearman_job): @auto_close_db def startThread(threadNumber): """Setup a gearman client, for the thread.""" - gm_worker = gearman.GearmanWorker([django_settings.GEARMAN_SERVER]) - hostID = gethostname() + "_" + threadNumber.__str__() - gm_worker.set_client_id(hostID) - for key in supportedModules.keys(): - logger.info('Registering: %s', key) - gm_worker.register_task(key, executeCommand) - - failMaxSleep = 30 - failSleep = 1 - failSleepIncrementor = 2 - while True: - try: - gm_worker.work() - except gearman.errors.ServerUnavailable as inst: - logger.error('Gearman server is unavailable: %s. Retrying in %d seconds.', inst.args, failSleep) - time.sleep(failSleep) - if failSleep < failMaxSleep: - failSleep += failSleepIncrementor + try: + gm_worker = gearman.GearmanWorker([django_settings.GEARMAN_SERVER]) + hostID = gethostname() + "_" + threadNumber.__str__() + gm_worker.set_client_id(hostID) + for key in supportedModules.keys(): + logger.info('Registering: %s', key) + gm_worker.register_task(key, executeCommand) + + failMaxSleep = 30 + failSleep = 1 + failSleepIncrementor = 2 + while True: + try: + gm_worker.work() + except gearman.errors.ServerUnavailable as inst: + logger.error('Gearman server is unavailable: %s. Retrying in %d seconds.', inst.args, failSleep) + time.sleep(failSleep) + if failSleep < failMaxSleep: + failSleep += failSleepIncrementor + except: + logger.error('Unable to create Gearman worker. Review "MCPClient" configuration item "MCPArchivematicaServer".') def startThreads(t=1):