Skip to content
Merged
Show file tree
Hide file tree
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: 13 additions & 5 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from pymongo.errors import DuplicateKeyError
from fastapi_users import FastAPIUsers
from beanie import PydanticObjectId
from pydantic import BaseModel
from kernelci.api.models import (

Check failure on line 38 in api/main.py

View workflow job for this annotation

GitHub Actions / Lint

Unable to import 'kernelci.api.models'
Node,
Hierarchy,
PublishEvent,
Expand All @@ -42,7 +43,6 @@
KernelVersion,
EventHistory,
)
from pydantic import BaseModel
from .auth import Authentication
from .db import Database
from .pubsub import PubSub
Expand All @@ -62,7 +62,6 @@
from .metrics import Metrics



@asynccontextmanager
async def lifespan(app: FastAPI): # pylint: disable=redefined-outer-name
"""Lifespan functions for startup and shutdown events"""
Expand Down Expand Up @@ -714,6 +713,17 @@
return obj


def is_same_flags(old_node, new_node):
""" Compare processed_by_kcidb_bridge flags
Returns True if flags are same, False otherwise
"""
old_flag = old_node.processed_by_kcidb_bridge
new_flag = new_node.processed_by_kcidb_bridge
if old_flag == new_flag:
return True
return False


@app.put('/node/{node_id}', response_model=Node, response_model_by_alias=False)
async def put_node(node_id: str, node: Node,
user: str = Depends(authorize_user),
Expand Down Expand Up @@ -757,9 +767,7 @@
# KCIDB flags are reset on any update, because this means we need
# to reprocess updated node.
# So reset flag, unless flag is changed in the request
old_flag = node_from_id.processed_by_kcidb_bridge
new_flag = node.processed_by_kcidb_bridge
if old_flag == new_flag:
if is_same_flags(node_from_id, node):
new_node_def.processed_by_kcidb_bridge = False

# Update node in the DB
Expand Down
10 changes: 9 additions & 1 deletion scripts/setup_admin_user
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/bash

# is docker-compose exists? if not use docker compose
if [ -z "$(which docker-compose)" ]; then
echo "docker-compose is not installed, using docker compose"
DOCKER_COMPOSE="docker compose"
else
DOCKER_COMPOSE="docker-compose"
fi

set -e

docker-compose run api python3 -m api.admin $*
${DOCKER_COMPOSE} run api python3 -m api.admin $*

exit 0
Loading