Skip to content

Commit

Permalink
MCPClient error check Gearman worker creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
minusdavid committed Aug 3, 2017
1 parent 9198655 commit e1accdd
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/MCPClient/lib/archivematicaClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +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):
"""Start a processing thread for each core (t=0), or a specified number of threads."""
Expand Down

0 comments on commit e1accdd

Please sign in to comment.