Stop harvesting job if the package extent could not be saved. Still shows an ugly SA exception

This commit is contained in:
Adrià Mercader 2011-03-29 17:23:49 +01:00
parent 95623b0f7a
commit d35f86f559
3 changed files with 24 additions and 10 deletions

View File

@ -118,10 +118,20 @@ class Harvester(CkanCommand):
packages = [extra.package \
for extra in \
Session.query(PackageExtra).filter(PackageExtra.key == 'bbox-east-long').all()]
for package in packages:
save_extent(package)
print "Done. Extents generated for %i packages" % len(packages)
error = False
for package in packages:
try:
save_extent(package)
except:
errors = True
if error:
msg = "There was an error saving the package extent. Have you set up the package_extent table in the DB?"
else:
msg = "Done. Extents generated for %i packages" % len(packages)
print msg
def run_harvester(self, *args, **kwds):
from pylons.i18n.translation import _get_translator

View File

@ -224,8 +224,7 @@ class HarvestingJobController(object):
# Create new package from data.
package = self._create_package_from_data(package_data)
if package.extras.get('bbox-east-long'):
save_extent(package)
self.save_package_extent(package)
log.info("Created new package ID %s with GEMINI guid %s", package.id, gemini_guid)
harvested_doc = HarvestedDocument(
content=content,
@ -241,8 +240,7 @@ class HarvestingJobController(object):
else:
package = self._create_package_from_data(package_data, package = package)
if package.extras.get('bbox-east-long'):
save_extent(package)
self.save_package_extent(package)
log.info("Updated existing package ID %s with existing GEMINI guid %s", package.id, gemini_guid)
harvested_doc.content = content
harvested_doc.source = self.job.source
@ -252,6 +250,13 @@ class HarvestingJobController(object):
assert gemini_guid == package.documents[0].guid
return package
def save_package_extent(self,package):
try:
save_extent(package)
except:
log.error("There was an error saving the package extent. Have you set up the package_extent table in the DB?")
raise Exception
def get_content(self, url):
try:
http_response = urllib2.urlopen(url)

View File

@ -106,8 +106,7 @@ def save_extent(package,extent=False):
Session.commit()
log.info(msg, package.id)
return package
except:
log.error('An error occurred when saving the extent for package %s',package.id)
finally:
return package
raise Exception