[#148] Catch a more specific exception.

This commit is contained in:
David Read 2015-10-01 12:30:40 +01:00
parent de17e0ae8c
commit 1a6dca7c00
1 changed files with 11 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import datetime
import json
import pika
import sqlalchemy
from ckan.lib.base import config
from ckan.plugins import PluginImplementations
@ -14,7 +15,7 @@ from ckanext.harvest.interfaces import IHarvester
log = logging.getLogger(__name__)
assert not log.disabled
__all__ = ['get_gather_publisher', 'get_gather_consumer', \
__all__ = ['get_gather_publisher', 'get_gather_consumer',
'get_fetch_publisher', 'get_fetch_consumer']
PORT = 5672
@ -211,11 +212,12 @@ def gather_callback(channel, method, header, body):
try:
job = HarvestJob.get(id)
except Exception, e:
# Occasionally we see:
# sqlalchemy.exc.OperationalError "SSL connection has been closed unexpectedly"
except sqlalchemy.exc.OperationalError, e:
# Occasionally we see: sqlalchemy.exc.OperationalError
# "SSL connection has been closed unexpectedly"
log.exception(e)
log.error('Connection Error during gather of %s: %r %r' % (id, e, e.args))
log.error('Connection Error during gather of job %s: %r %r',
id, e, e.args)
# By not sending the ack, it will be retried later.
# Try to clear the issue with a remove.
model.Session.remove()
@ -291,11 +293,12 @@ def fetch_callback(channel, method, header, body):
try:
obj = HarvestObject.get(id)
except Exception, e:
except sqlalchemy.exc.OperationalError, e:
# Occasionally we see: sqlalchemy.exc.OperationalError
# "SSL connection has been closed unexpectedly"
log.exception(e)
log.error('Connection Error during gather of %s: %r %r' % (id, e, e.args))
log.error('Connection Error during gather of harvest object %s: %r %r',
id, e, e.args)
# By not sending the ack, it will be retried later.
# Try to clear the issue with a remove.
model.Session.remove()