Skip to content

Commit

Permalink
Multiple quality fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
djspstfc committed Jul 18, 2024
1 parent ea9d0f2 commit bd2920f
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/esgf-api-ingest-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ jobs:
cd esgf-api-ingest
pip install poetry
poetry self add poetry-audit-plugin
poetry audit
poetry audit --ignore-code=CVE-2019-8341
- name: Run xenon
run: |
cd esgf-api-ingest
pip install poetry
poetry install --only xenon
poetry audit
poetry run xenon . -a A -b A -m A
2 changes: 1 addition & 1 deletion .github/workflows/esgf-consumer-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
cd esgf-consumer
pip install poetry
poetry install --only xenon
poetry audit
poetry run xenon . -a A -b A -m A
2 changes: 1 addition & 1 deletion .github/workflows/esgf-generator-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
cd esgf-generator
pip install poetry
poetry install --only xenon
poetry audit
poetry run xenon . -a A -b A -m A
2 changes: 1 addition & 1 deletion .github/workflows/esgf-playground-utils-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
cd esgf-playground-utils
pip install poetry
poetry install --only xenon
poetry audit
poetry run xenon . -a A -b A -m A
21 changes: 8 additions & 13 deletions esgf-api-ingest/esgf_api_ingest/main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import asyncio
import json
import logging
import os
from contextlib import asynccontextmanager
from datetime import datetime
from typing import Any, AsyncGenerator, NoReturn, Optional, Union
from typing import Any, AsyncGenerator, Optional, Union

import aiokafka
from esgf_playground_utils.config.kafka import Settings
from esgf_playground_utlis.models.kafka import (
Auth,
CreatePayload,
Data,
KafkaEvent,
Metadata,
Publisher,
)
from esgf_playground_utlis.models.kafka import (Auth, CreatePayload, Data,
KafkaEvent, Metadata,
Publisher)
from fastapi import FastAPI, HTTPException
from stac_pydantic.item import Item
from stac_pydantic.item_collection import ItemCollection
Expand Down Expand Up @@ -53,6 +45,9 @@ async def post_message(event: KafkaEvent) -> None:
value = event.model_dump_json().encode("utf8")
topic = get_topic(event.data.payload.item)

if producer is None:
raise Exception("Kafka producer is not initialized")

await producer.send_and_wait(topic, value)
except Exception as exc:
raise HTTPException(status_code=500, detail=repr(exc)) from exc
Expand All @@ -67,7 +62,7 @@ async def post_item(collection_id: str, item: Item) -> None:
auth=auth, publisher=publisher, time=datetime.now(), schema_version="1.0.0"
)
event = KafkaEvent(metadata=metadata, data=data)
post_message(event)
await post_message(event)


@app.post("/{collection_id}/items", status_code=202)
Expand Down
5 changes: 3 additions & 2 deletions esgf-consumer/esgf_consumer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import httpx
from aiokafka.errors import KafkaError
from esgf_playground_utils.models.kafka import Error, ErrorType, KafkaEvent
from pydantic import ValidationError

from esgf_consumer.collection import ensure_collection
from esgf_consumer.config import Settings
from esgf_consumer.consumers import get_consumer
from esgf_consumer.items import create_item
from esgf_consumer.producers import get_producer
from esgf_playground_utils.models.kafka import Error, ErrorType, KafkaEvent
from pydantic import ValidationError

logging.getLogger().setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion esgf-consumer/esgf_consumer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import logging

import click
from esgf_consumer import consume
from esgf_playgroud_utils.config.kafka import Settings

from esgf_consumer import consume

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

Expand Down
3 changes: 2 additions & 1 deletion esgf-consumer/esgf_consumer/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from urllib.parse import urljoin

import httpx
from esgf_consumer.config import Settings
from stac_pydantic.item import Item

from esgf_consumer.config import Settings

logger = logging.getLogger(__name__)


Expand Down

0 comments on commit bd2920f

Please sign in to comment.