Stop harvesting job if the package extent could not be saved. Still shows an ugly SA exception
This commit is contained in:
parent
95623b0f7a
commit
d35f86f559
|
@ -118,10 +118,20 @@ class Harvester(CkanCommand):
|
||||||
packages = [extra.package \
|
packages = [extra.package \
|
||||||
for extra in \
|
for extra in \
|
||||||
Session.query(PackageExtra).filter(PackageExtra.key == 'bbox-east-long').all()]
|
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):
|
def run_harvester(self, *args, **kwds):
|
||||||
from pylons.i18n.translation import _get_translator
|
from pylons.i18n.translation import _get_translator
|
||||||
|
|
|
@ -224,8 +224,7 @@ class HarvestingJobController(object):
|
||||||
# Create new package from data.
|
# Create new package from data.
|
||||||
package = self._create_package_from_data(package_data)
|
package = self._create_package_from_data(package_data)
|
||||||
if package.extras.get('bbox-east-long'):
|
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)
|
log.info("Created new package ID %s with GEMINI guid %s", package.id, gemini_guid)
|
||||||
harvested_doc = HarvestedDocument(
|
harvested_doc = HarvestedDocument(
|
||||||
content=content,
|
content=content,
|
||||||
|
@ -241,8 +240,7 @@ class HarvestingJobController(object):
|
||||||
else:
|
else:
|
||||||
package = self._create_package_from_data(package_data, package = package)
|
package = self._create_package_from_data(package_data, package = package)
|
||||||
if package.extras.get('bbox-east-long'):
|
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)
|
log.info("Updated existing package ID %s with existing GEMINI guid %s", package.id, gemini_guid)
|
||||||
harvested_doc.content = content
|
harvested_doc.content = content
|
||||||
harvested_doc.source = self.job.source
|
harvested_doc.source = self.job.source
|
||||||
|
@ -252,6 +250,13 @@ class HarvestingJobController(object):
|
||||||
assert gemini_guid == package.documents[0].guid
|
assert gemini_guid == package.documents[0].guid
|
||||||
return package
|
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):
|
def get_content(self, url):
|
||||||
try:
|
try:
|
||||||
http_response = urllib2.urlopen(url)
|
http_response = urllib2.urlopen(url)
|
||||||
|
|
|
@ -106,8 +106,7 @@ def save_extent(package,extent=False):
|
||||||
|
|
||||||
Session.commit()
|
Session.commit()
|
||||||
log.info(msg, package.id)
|
log.info(msg, package.id)
|
||||||
|
return package
|
||||||
except:
|
except:
|
||||||
log.error('An error occurred when saving the extent for package %s',package.id)
|
log.error('An error occurred when saving the extent for package %s',package.id)
|
||||||
finally:
|
raise Exception
|
||||||
return package
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue