Skip to content

Commit

Permalink
Improve recalculate_bits endpoint logging
Browse files Browse the repository at this point in the history
Add valid_time as optional parameter to upgrade function
Fix integration test with unwanted deletion propagation happening

Signed-off-by: Donny Peeters <donny@bitestreams.com>
  • Loading branch information
Donnype committed Jul 25, 2024
1 parent 18914bc commit 6e165db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions boefjes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ bench: ## Run the report benchmark.
$(ci-docker-compose) build
$(ci-docker-compose) down --remove-orphans
$(ci-docker-compose) run --rm migration_bench
$(ci-docker-compose) stop

debian12:
docker run --rm \
Expand Down
2 changes: 1 addition & 1 deletion boefjes/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def seed_system(
Observation(
method="",
source_method="test",
source=network.reference,
source=hostnames[0].reference,
task_id=uuid.uuid4(),
valid_time=valid_time,
result=oois,
Expand Down
2 changes: 1 addition & 1 deletion boefjes/tests/integration/test_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_migration(octopoes_api_connector: OctopoesAPIConnector, bytes_client: B

bytes_client.save_normalizer_meta(normalizer_meta)

total_processed, total_failed = upgrade()
total_processed, total_failed = upgrade(valid_time)

assert total_processed == 0
assert total_failed == 0
7 changes: 5 additions & 2 deletions boefjes/tools/upgrade_v1_16_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
logger = logging.getLogger(__name__)


def upgrade() -> tuple[int, int]:
def upgrade(valid_time: datetime | None = None) -> tuple[int, int]:
"""
Perform the migration for all organisations in the database. The happy flow in this script is idempotent,
meaning that it can be rerun until there are no, or only expected, exceptions.
"""

organisations = create_organisation_storage(sessionmaker(bind=get_engine())()).get_all()
valid_time = datetime.now(timezone.utc)

if valid_time is None:
valid_time = datetime.now(timezone.utc)

bytes_client = get_bytes_client()
bytes_client.login()
Expand All @@ -60,6 +62,7 @@ def upgrade() -> tuple[int, int]:

return total_processed, total_failed


def migrate_org(bytes_client, connector, organisation_id, valid_time) -> tuple[int, int]:
"""
For each organisation, we paginate through the origin API, find the matching normalizer meta in Bytes,
Expand Down
7 changes: 6 additions & 1 deletion octopoes/octopoes/api/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,12 @@ def delete_node(xtdb_session_: XTDBSession = Depends(xtdb_session)) -> None:

@router.post("/bits/recalculate", tags=["Bits"])
def recalculate_bits(octopoes: OctopoesService = Depends(octopoes_service)) -> int:
inference_count = octopoes.recalculate_bits()
try:
inference_count = octopoes.recalculate_bits()
except ObjectNotFoundException:
logger.exception("Failed to recalculate bits")
raise

octopoes.commit()

return inference_count
Expand Down

0 comments on commit 6e165db

Please sign in to comment.