Skip to content

Commit

Permalink
merge from harvest-db-update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin-Sun-tts committed Mar 20, 2024
2 parents ee8f777 + eb136bd commit 5d7c1e9
Show file tree
Hide file tree
Showing 17 changed files with 537 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ S3FILESTORE__SIGNATURE_VERSION=s3v4

MDTRANSLATOR_URL=http://127.0.0.1:3000/translates

DATABASE_SERVER=db
DATABASE_SERVER=localhost
DATABASE_PORT=5432
DATABASE_NAME=mydb
DATABASE_USER=myuser
Expand Down
3 changes: 3 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from .models import db
from flask_migrate import Migrate
import os
from dotenv import load_dotenv

load_dotenv()

DATABASE_URI = os.getenv('DATABASE_URI')

Expand Down
8 changes: 5 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class HarvestError(Base):
harvest_job_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('harvest_job.id'),
nullable=False)
harvest_record_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('harvest_record.id'),
nullable=True)
harvest_record_id = db.Column(db.String)
# to-do
# harvest_record_id = db.Column(UUID(as_uuid=True),
# db.ForeignKey('harvest_record.id'),
# nullable=True)
date_created = db.Column(db.DateTime)
type = db.Column(db.String)
severity = db.Column(Enum('CRITICAL', 'ERROR', 'WARN', name='error_serverity'),
Expand Down
3 changes: 3 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ <h2>Harvest Actions</h2>
<li><a href="/add_org">Add Organization</a></li>
<li><a href="/add_source">Add Harvest Source</a></li>
<li><a href="/add_job">Add Harvest Job</a></li>
<li><a href="/add_error">Add Harvest Error</a></li>
<li><a href="/organizations">Get All Organizations</a></li>
<li><a href="/harvest_sources">Get All Harvest Sources</a></li>
<li><a href="/harvest_jobs">Get All Harvest Jobs</a></li>
<li><a href="/harvest_errors_by_job/<job_id>">Get All Harvest Errors By Job</a></li>
<li><a href="/harvest_source/<source_id>">Get Harvest Source</a></li>
<li><a href="/harvest_job/<job_id>">Get Harvest Job</a></li>
<li><a href="/harvest_error/<error_id>">Get Harvest Error</a></li>
</ul>
</body>
</html>
8 changes: 7 additions & 1 deletion harvester/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
from .harvest import HarvestSource, Record # noqa
import logging.config
from harvester.logger_config import LOGGING_CONFIG
from dotenv import load_dotenv

load_dotenv()

logging.config.dictConfig(LOGGING_CONFIG)
43 changes: 0 additions & 43 deletions harvester/data/dcatus/jsons/null-spatial.data.json

This file was deleted.

83 changes: 83 additions & 0 deletions harvester/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import logging
from datetime import datetime
from app.interface import HarvesterDBInterface


# critical exceptions
class HarvestCriticalException(Exception):
def __init__(self, msg, harvest_job_id):
super().__init__(msg, harvest_job_id)

self.msg = msg
self.harvest_job_id = harvest_job_id
self.severity = "CRITICAL"
self.type = "job"

self.db_interface = HarvesterDBInterface()
self.logger = logging.getLogger("harvest_runner")

error_data = {
"harvest_job_id": self.harvest_job_id,
"message": self.msg,
"severity": self.severity,
"type": self.type,
"date_created": datetime.utcnow(),
}

self.db_interface.add_harvest_error(error_data, self.harvest_job_id)
self.logger.critical(self.msg, exc_info=True)


class ExtractHarvestSourceException(HarvestCriticalException):
pass


class ExtractCKANSourceException(HarvestCriticalException):
pass


class CompareException(HarvestCriticalException):
pass


# non-critical exceptions
class HarvestNonCriticalException(Exception):
def __init__(self, msg, harvest_job_id, title):
super().__init__(msg, harvest_job_id, title)

self.title = title
self.msg = msg
self.harvest_job_id = harvest_job_id
self.severity = "ERROR"
self.type = "record"

self.db_interface = HarvesterDBInterface()
self.logger = logging.getLogger("harvest_runner")

error_data = {
"harvest_job_id": self.harvest_job_id,
"message": self.msg,
"severity": self.severity,
"type": self.type,
"date_created": datetime.utcnow(),
"harvest_record_id": self.title # to-do
}

self.db_interface.add_harvest_error(error_data, self.harvest_job_id)
self.logger.error(self.msg, exc_info=True)


class ValidationException(HarvestNonCriticalException):
pass


class TranformationException(HarvestNonCriticalException):
pass


class DCATUSToCKANException(HarvestNonCriticalException):
pass


class SynchronizeException(HarvestNonCriticalException):
pass
Loading

1 comment on commit 5d7c1e9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
harvester
   __init__.py50100% 
   ckan_utils.py4222 95%
   exceptions.py420100% 
   harvest.py4256565 85%
   logger_config.py10100% 
   utils.py3522 94%
TOTAL5506987% 

Tests Skipped Failures Errors Time
28 0 💤 0 ❌ 0 🔥 2.639s ⏱️

Please sign in to comment.