Skip to content

Commit

Permalink
Merge branch 'db-error'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Nov 20, 2015
2 parents ede50aa + 59be6e2 commit 920df68
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions ckanext/harvest/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import json

import pika
import sqlalchemy

from ckan.lib.base import config
from ckan.plugins import PluginImplementations
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

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -221,8 +222,18 @@ def gather_callback(channel, method, header, body):
# Get a publisher for the fetch queue
publisher = get_fetch_publisher()

job = HarvestJob.get(id)

try:
job = HarvestJob.get(id)
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 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()
return
if not job:
log.error('Harvest job does not exist: %s' % id)
channel.basic_ack(method.delivery_tag)
Expand Down Expand Up @@ -313,7 +324,18 @@ def fetch_callback(channel, method, header, body):
channel.basic_ack(method.delivery_tag)
return False

obj = HarvestObject.get(id)
try:
obj = HarvestObject.get(id)
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 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()
return
if not obj:
log.error('Harvest object does not exist: %s' % id)
channel.basic_ack(method.delivery_tag)
Expand Down

0 comments on commit 920df68

Please sign in to comment.