Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(main.py): Store events in eventhistory collection #562

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
from pymongo.errors import DuplicateKeyError
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from kernelci.api.models import (

Check failure on line 34 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
parse_node_obj,
KernelVersion,
EventHistory,
)
from .auth import Authentication
from .db import Database
Expand Down Expand Up @@ -114,7 +115,7 @@

metrics = Metrics()

app = FastAPI(lifespan=lifespan)
app = FastAPI(lifespan=lifespan, debug=True)
db = Database(service=(os.getenv('MONGO_SERVICE') or 'mongodb://db:27017'))
auth = Authentication(token_url="user/login")
pubsub = None # pylint: disable=invalid-name
Expand Down Expand Up @@ -487,6 +488,15 @@
await db.delete_by_id(UserGroup, group_id)


# -----------------------------------------------------------------------------
# EventHistory
def _get_eventhistory(evdict):
"""Get EventHistory object from dictionary"""
evhist = EventHistory()
evhist.data = evdict
return evhist


# -----------------------------------------------------------------------------
# Nodes

Expand Down Expand Up @@ -650,6 +660,8 @@
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj


Expand Down Expand Up @@ -695,6 +707,8 @@
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj


Expand Down Expand Up @@ -735,6 +749,8 @@
if data.get('owner', None):
attributes['owner'] = data['owner']
await pubsub.publish_cloudevent('node', data, attributes)
evhist = _get_eventhistory(data)
await db.create(evhist)
return obj_list


Expand Down
Loading