Skip to content

Commit

Permalink
Merge branch 'main' into snyk-upgrade-4b667552b73f225de251706f4b390969
Browse files Browse the repository at this point in the history
  • Loading branch information
btylerburton authored Jan 13, 2025
2 parents ffecb40 + 6b4aeb4 commit 55405c8
Show file tree
Hide file tree
Showing 19 changed files with 1,742 additions and 1,484 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: Tests on Commit
on: [push]

env:
PY_VERSION: "3.10"
POETRY_VERSION: "1.7.1"
PY_VERSION: "3.13"
POETRY_VERSION: "2.0.0"

jobs:
lint:
Expand Down Expand Up @@ -38,6 +38,7 @@ jobs:
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
poetry-plugins: "poetry-plugin-export"

- name: Install Dependencies
run: |
Expand Down Expand Up @@ -77,6 +78,7 @@ jobs:
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
poetry-plugins: "poetry-plugin-export"
- name: Add requirement.txt
run: |
poetry export -f requirements.txt --output requirements.txt --without-hashes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
required: true

env:
POETRY_VERSION: "1.7.1"
POETRY_VERSION: "2.0.0"

jobs:
deploy-staging:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/load_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Load Test
on:
workflow_dispatch:

jobs:
load-test:
name: H2.0 Load Test
Expand All @@ -12,7 +12,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.13
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install Poetry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
required: true

env:
POETRY_VERSION: "1.7.1"
POETRY_VERSION: "2.0.0"

jobs:
publish:
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.0
3.13.0
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python:3.10
FROM python:3.13

WORKDIR /app

COPY . /app

RUN pip install --no-cache-dir -r requirements.txt

ARG DEV
ARG DEV

RUN if [ $DEV ]; \
then pip install --no-cache-dir -r requirements-dev.txt; \
Expand All @@ -17,4 +17,4 @@ EXPOSE 8080
ENV FLASK_APP=run.py

# Run run.py when the container launches
CMD ["flask", "run", "--host=0.0.0.0", "--port=8080"]
CMD ["flask", "run", "--host=0.0.0.0", "--port=8080"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test-integration: ## Runs integration tests. Compatible with dev environment / `
poetry run pytest --junitxml=pytest.xml --cov=harvester ./tests/integration

test-functional: ## Runs integration tests. Compatible with dev environment / `make up`
poetry run pytest --noconftest --junitxml=pytest.xml --cov=harvester ./tests/functional
poetry run pytest --noconftest --junitxml=pytest.xml ./tests/functional

test: up test-unit test-integration ## Runs all tests. Compatible with dev environment / `make up`

Expand Down
9 changes: 5 additions & 4 deletions app/static/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"@uswds/uswds": "3.9.0",
"chart.js": "^4.4.5",
"htmx.org": "^2.0.2",
"htmx.org": "^2.0.3",
"rollup": "^4.24.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions harvester/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import logging.config
import os

from dotenv import load_dotenv

from config.logger_config import LOGGING_CONFIG
from database.interface import HarvesterDBInterface

import os

load_dotenv()

logging.config.dictConfig(LOGGING_CONFIG)
Expand All @@ -21,5 +20,5 @@
"password": os.getenv("HARVEST_SMTP_PASSWORD"),
"default_sender": os.getenv("HARVEST_SMTP_SENDER"),
"base_url": os.getenv("REDIRECT_URI").rsplit("/", 1)[0],
"recipient": os.getenv("HARVEST_SMTP_RECIPIENT")
"recipient": os.getenv("HARVEST_SMTP_RECIPIENT"),
}
76 changes: 38 additions & 38 deletions harvester/harvest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

sys.path.insert(1, "/".join(os.path.realpath(__file__).split("/")[0:-2]))

from harvester import SMTP_CONFIG
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

from harvester import HarvesterDBInterface, db_interface
from harvester import SMTP_CONFIG, HarvesterDBInterface, db_interface
from harvester.exceptions import (
CompareException,
DCATUSToCKANException,
Expand Down Expand Up @@ -73,7 +72,7 @@ class HarvestSource:
"schema_type",
"source_type",
"id", # db guuid
"notification_emails"
"notification_emails",
],
repr=False,
)
Expand Down Expand Up @@ -162,7 +161,6 @@ def internal_records_to_id_hash(self, records: list[dict]) -> None:
)

def get_record_identifier(self, record: dict) -> str:

record_id = "identifier" if self.schema_type.startswith("dcatus") else "url"

if record_id not in record:
Expand All @@ -181,7 +179,6 @@ def external_records_to_id_hash(self, records: list[dict]) -> None:
logger.info("converting harvest records to id: hash")
for record in records:
try:

identifier = self.get_record_identifier(record)

if self.source_type == "document":
Expand All @@ -196,7 +193,7 @@ def external_records_to_id_hash(self, records: list[dict]) -> None:
except Exception as e:
# TODO: do something with 'e'
raise ExtractExternalException(
f"{self.title} {self.url} failed to convert to id:hash",
f"{self.name} {self.url} failed to convert to id:hash",
self.job_id,
)

Expand Down Expand Up @@ -248,7 +245,7 @@ def compare(self) -> None:
except Exception as e:
# TODO: do something with 'e'
raise CompareException(
f"{self.title} {self.url} failed to run compare. exiting.",
f"{self.name} {self.url} failed to run compare. exiting.",
self.job_id,
)

Expand Down Expand Up @@ -402,45 +399,45 @@ def report(self) -> None:
self.send_notification_emails(actual_results_action)

def send_notification_emails(self, results: dict) -> None:
try:
job_url = f'{SMTP_CONFIG["base_url"]}/harvest_job/{self.job_id}'

subject = "Harvest Job Completed"
body = (
f"The harvest job ({self.job_id}) has been successfully completed.\n"
f"You can view the details here: {job_url}\n\n"
"Summary of the job:\n"
f"- Records Added: {results['create']}\n"
f"- Records Updated: {results['update']}\n"
f"- Records Deleted: {results['delete']}\n"
f"- Records Ignored: {results[None]}\n\n"
"====\n"
"You received this email because you subscribed to harvester updates.\n"
"Please do not reply to this email, as it is not monitored."
)
support_recipient = SMTP_CONFIG.get("recipient")
user_recipients = self.notification_emails
all_recipients = [support_recipient] + user_recipients
job_url = f'{SMTP_CONFIG["base_url"]}/harvest_job/{self.job_id}'

subject = "Harvest Job Completed"
body = (
f"The harvest job ({self.job_id}) has been successfully completed.\n"
f"You can view the details here: {job_url}\n\n"
"Summary of the job:\n"
f"- Records Added: {results['create']}\n"
f"- Records Updated: {results['update']}\n"
f"- Records Deleted: {results['delete']}\n"
f"- Records Ignored: {results[None]}\n\n"
"====\n"
"You received this email because you subscribed to harvester updates.\n"
"Please do not reply to this email, as it is not monitored."
)
support_recipient = SMTP_CONFIG.get("recipient")
user_recipients = self.notification_emails
all_recipients = [support_recipient] + user_recipients

msg = MIMEMultipart()
msg["From"] = SMTP_CONFIG["default_sender"]
msg["Reply-To"] = "[email protected]"
msg["Subject"] = subject
msg.attach(MIMEText(body, "plain"))

try:
with smtplib.SMTP(SMTP_CONFIG["server"], SMTP_CONFIG["port"]) as server:
if SMTP_CONFIG["use_tls"]:
server.starttls()
server.login(SMTP_CONFIG["username"], SMTP_CONFIG["password"])

for recipient in all_recipients:
msg = MIMEMultipart()
msg["From"] = SMTP_CONFIG["default_sender"]
msg["To"] = recipient
msg["Reply-To"] = "[email protected]"
msg["Subject"] = subject
msg.attach(MIMEText(body, "plain"))

server.sendmail(SMTP_CONFIG["default_sender"], [recipient],
msg.as_string())
server.sendmail(
SMTP_CONFIG["default_sender"], [recipient], msg.as_string()
)
logger.info(f"Notification email sent to: {recipient}")

except Exception as e:
logger.error(f"Error preparing or sending notification emails: {e}")
logger.error(f"Failed to send notification email: {e}")


@dataclass
Expand Down Expand Up @@ -565,7 +562,6 @@ def status(self, value) -> None:
self._status = value

def transform(self) -> None:

data = {
"file": self.metadata["content"],
"reader": self.reader_map[self.harvest_source.schema_type],
Expand All @@ -584,7 +580,11 @@ def transform(self) -> None:
self.harvest_source.internal_records_lookup_table[self.identifier],
)

record_id = self.harvest_source.internal_records_lookup_table[self.identifier]
if 200 <= resp.status_code < 300:
logger.info(
f"successfully transformed record: {self.identifier} db id: {record_id}"
)
self.transformed_data = json.loads(data["writerOutput"])

def validate(self) -> None:
Expand Down
Loading

1 comment on commit 55405c8

@github-actions
Copy link

Choose a reason for hiding this comment

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

Tests Skipped Failures Errors Time
2 0 💤 0 ❌ 0 🔥 7.041s ⏱️

Please sign in to comment.