Skip to content

Commit 7557bf4

Browse files
Complexity Based Consumption (#59)
* add update logic for cognition complexity * Submodule update --------- Co-authored-by: JWittmeyer <jens.wittmeyer@kern.ai>
1 parent 8881cf6 commit 7557bf4

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

start

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ docker run -d --rm \
1919
-e S3_ACCESS_KEY=onetask \
2020
-e S3_SECRET_KEY=r6ywtR33!DMlaL*SUUdy \
2121
-e NEURAL_SEARCH=http://refinery-neural-search:80 \
22+
-e COGNITION_GATEWAY=http://cognition-gateway:80 \
2223
-e POSTGRES=postgresql://postgres:onetask@graphql-postgres:5432 \
2324
--mount type=bind,source="$(pwd)"/,target=/app \
2425
-v /var/run/docker.sock:/var/run/docker.sock \

upgrade_logic/business_objects/gateway.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import re
3+
import requests
24
from config_handler import get_config_value
35
from submodules.model.business_objects import (
46
attribute,
@@ -9,6 +11,46 @@
911
from submodules.model import enums
1012

1113

14+
def gateway_1_14_0() -> bool:
15+
# here, we update data for cognition using the gateway pattern
16+
# as the corresponding database updates (alembic) are managed using the refinery gateway it is
17+
# ensured that these updates are executed at the correct time
18+
gateway_1_14_0_add_cognition_project_state()
19+
gateway_1_14_0_add_cognition_strategy_complexity()
20+
return True
21+
22+
23+
def gateway_1_14_0_add_cognition_project_state() -> bool:
24+
query = f"""
25+
UPDATE cognition.project
26+
SET state = '{enums.CognitionProjectState.PRODUCTION.value}'
27+
WHERE state IS NULL
28+
"""
29+
general.execute(query)
30+
general.commit()
31+
return True
32+
33+
34+
def gateway_1_14_0_add_cognition_strategy_complexity() -> bool:
35+
cognition_url = os.getenv("COGNITION_GATEWAY")
36+
if not cognition_url:
37+
print(
38+
"No cognition gateway url found. Skipping cognition strategy complexity update."
39+
)
40+
return False
41+
42+
response = requests.post(
43+
f"{cognition_url}/api/v1/strategies/internal/calculate_missing_complexities"
44+
)
45+
if response.status_code != 200:
46+
print(
47+
f"Failed to update cognition strategy complexities. Status code: {response.status_code}"
48+
)
49+
return False
50+
51+
return True
52+
53+
1254
def gateway_1_10_1() -> bool:
1355
__gateway_1_10_1_add_additional_embedding_information()
1456
return True

0 commit comments

Comments
 (0)