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