Merge branch 'db-error'

This commit is contained in:
amercader 2015-11-20 12:29:37 +00:00
commit 920df684ae
1 changed files with 26 additions and 4 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
@ -221,8 +222,18 @@ def gather_callback(channel, method, header, body):
# Get a publisher for the fetch queue
publisher = get_fetch_publisher()
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)
@ -313,7 +324,18 @@ def fetch_callback(channel, method, header, body):
channel.basic_ack(method.delivery_tag)
return False
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)