wip
This commit is contained in:
parent
f5237c1273
commit
7e1a9fcf75
12 changed files with 27 additions and 25 deletions
|
|
@ -2,7 +2,7 @@ from chalicelib.utils import pg_client, helper
|
|||
|
||||
|
||||
async def get_all_alerts():
|
||||
async with pg_client.cursor(long_query=True) as cur:
|
||||
async with pg_client.cursor() as cur:
|
||||
query = """SELECT -1 AS tenant_id,
|
||||
alert_id,
|
||||
projects.project_id,
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ def can_check(a) -> bool:
|
|||
and ((now - a["createdAt"]) % (TimeInterval[repetitionBase] * 60 * 1000)) < 60 * 1000
|
||||
|
||||
|
||||
def Build(a):
|
||||
async def Build(a):
|
||||
now = TimeUTC.now()
|
||||
params = {"project_id": a["projectId"], "now": now}
|
||||
full_args = {}
|
||||
|
|
@ -186,13 +186,18 @@ def Build(a):
|
|||
return q, params
|
||||
|
||||
|
||||
async def process():
|
||||
def process():
|
||||
import asyncio
|
||||
asyncio.run(_process())
|
||||
|
||||
|
||||
async def _process():
|
||||
notifications = []
|
||||
all_alerts = alerts_listener.get_all_alerts()
|
||||
async with pg_client.cursor() as cur:
|
||||
for alert in all_alerts:
|
||||
if can_check(alert):
|
||||
query, params = Build(alert)
|
||||
query, params = await Build(alert)
|
||||
try:
|
||||
query = cur.mogrify(query, params)
|
||||
except Exception as e:
|
||||
|
|
@ -219,7 +224,7 @@ async def process():
|
|||
SET options = options||'{{"lastNotification":{TimeUTC.now()}}}'::jsonb
|
||||
WHERE alert_id IN %(ids)s;""", {"ids": tuple([n["alertId"] for n in notifications])}))
|
||||
if len(notifications) > 0:
|
||||
alerts.process_notifications(notifications)
|
||||
await alerts.process_notificationsq(notifications)
|
||||
|
||||
|
||||
def __format_value(x):
|
||||
|
|
|
|||
|
|
@ -681,7 +681,7 @@ ACTION_STATE = {
|
|||
|
||||
|
||||
async def change_state(project_id, user_id, error_id, action):
|
||||
errors = get(error_id, family=True)
|
||||
errors = await get(error_id, family=True)
|
||||
print(len(errors))
|
||||
status = ACTION_STATE.get(action)
|
||||
if errors is None or len(errors) == 0:
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ async def update_feature_flag(project_id: int, feature_flag_id: int,
|
|||
"""
|
||||
Update an existing feature flag and return its updated data.
|
||||
"""
|
||||
validate_unique_flag_key(feature_flag_data=feature_flag, project_id=project_id, exclude_id=feature_flag_id)
|
||||
await validate_unique_flag_key(feature_flag_data=feature_flag, project_id=project_id, exclude_id=feature_flag_id)
|
||||
validate_multi_variant_flag(feature_flag_data=feature_flag)
|
||||
|
||||
columns = (
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ async def get_health():
|
|||
"details": __get_sessions_stats,
|
||||
"ssl": __check_SSL
|
||||
}
|
||||
return __process_health(health_map=health_map)
|
||||
return await __process_health(health_map=health_map)
|
||||
|
||||
|
||||
async def __process_health(health_map):
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ def __find_streams(project_id, log_group, client, token, stream_filter):
|
|||
data = client.describe_log_streams(**d_args)
|
||||
streams = list(filter(stream_filter, data['logStreams']))
|
||||
if 'nextToken' not in data:
|
||||
save_new_token(project_id=project_id, token=token)
|
||||
await save_new_token(project_id=project_id, token=token)
|
||||
return streams
|
||||
return streams + __find_streams(project_id, log_group, client, data['nextToken'], stream_filter)
|
||||
|
||||
|
|
|
|||
|
|
@ -295,13 +295,13 @@ async def get_errors_trend(project_id, startTimestamp=TimeUTC.now(delta_days=-1)
|
|||
async def get_page_metrics(project_id, startTimestamp=TimeUTC.now(delta_days=-1),
|
||||
endTimestamp=TimeUTC.now(), **args):
|
||||
async with pg_client.cursor() as cur:
|
||||
rows = __get_page_metrics(cur, project_id, startTimestamp, endTimestamp, **args)
|
||||
rows = await __get_page_metrics(cur, project_id, startTimestamp, endTimestamp, **args)
|
||||
if len(rows) > 0:
|
||||
results = helper.dict_to_camel_case(rows[0])
|
||||
diff = endTimestamp - startTimestamp
|
||||
endTimestamp = startTimestamp
|
||||
startTimestamp = endTimestamp - diff
|
||||
rows = __get_page_metrics(cur, project_id, startTimestamp, endTimestamp, **args)
|
||||
rows = await __get_page_metrics(cur, project_id, startTimestamp, endTimestamp, **args)
|
||||
if len(rows) > 0:
|
||||
previous = helper.dict_to_camel_case(rows[0])
|
||||
for key in previous.keys():
|
||||
|
|
|
|||
|
|
@ -411,7 +411,6 @@ async def update_project_conditions(project_id, conditions):
|
|||
await create_project_conditions(project_id, to_be_created)
|
||||
|
||||
if to_be_updated:
|
||||
print(to_be_updated)
|
||||
await update_project_condition(project_id, to_be_updated)
|
||||
|
||||
return await get_conditions(project_id)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ async def create_new_assignment(tenant_id, project_id, session_id, creator_id, a
|
|||
if error is not None:
|
||||
return error
|
||||
|
||||
i = integration.get()
|
||||
i = await integration.get()
|
||||
|
||||
if i is None:
|
||||
return {"errors": [f"integration not found"]}
|
||||
|
|
@ -76,7 +76,7 @@ async def get_all(project_id, user_id):
|
|||
""",
|
||||
{"project_id": project_id,
|
||||
"providers": tuple(d for d in available_integrations if available_integrations[d])})
|
||||
cur.execute(
|
||||
await cur.execute(
|
||||
query
|
||||
)
|
||||
assignments = helper.list_to_camel_case(await cur.fetchall())
|
||||
|
|
@ -97,7 +97,7 @@ async def get_by_session(tenant_id, user_id, project_id, session_id):
|
|||
WHERE {" AND ".join(extra_query)};""",
|
||||
{"session_id": session_id,
|
||||
"providers": tuple([k for k in available_integrations if available_integrations[k]])})
|
||||
cur.execute(
|
||||
await cur.execute(
|
||||
query
|
||||
)
|
||||
results = await cur.fetchall()
|
||||
|
|
|
|||
|
|
@ -73,9 +73,7 @@ async def create_tenant(data: schemas.UserSignupSchema):
|
|||
RETURNING project_id, (SELECT api_key FROM t) AS api_key;"""
|
||||
|
||||
async with pg_client.cursor() as cur:
|
||||
print('fuuuu')
|
||||
await cur.execute(cur.mogrify(query, params))
|
||||
print('barrr')
|
||||
await telemetry.new_client()
|
||||
r = await users.authenticate(email, password)
|
||||
r["smtp"] = smtp.has_smtp()
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ async def edit_member(user_id_to_update, tenant_id, changes: schemas.EditMemberS
|
|||
user = await get_member(user_id=user_id_to_update, tenant_id=tenant_id)
|
||||
_changes = {}
|
||||
if editor_id != user_id_to_update:
|
||||
admin = get_user_role(tenant_id=tenant_id, user_id=editor_id)
|
||||
admin = await get_user_role(tenant_id=tenant_id, user_id=editor_id)
|
||||
if not admin["superAdmin"] and not admin["admin"]:
|
||||
return {"errors": ["unauthorized"]}
|
||||
if admin["admin"] and user["superAdmin"]:
|
||||
|
|
@ -297,8 +297,8 @@ async def edit_member(user_id_to_update, tenant_id, changes: schemas.EditMemberS
|
|||
_changes["role"] = "admin" if changes.admin else "member"
|
||||
|
||||
if len(_changes.keys()) > 0:
|
||||
update(tenant_id=tenant_id, user_id=user_id_to_update, changes=_changes, output=False)
|
||||
return {"data": get_member(user_id=user_id_to_update, tenant_id=tenant_id)}
|
||||
await update(tenant_id=tenant_id, user_id=user_id_to_update, changes=_changes, output=False)
|
||||
return {"data": await get_member(user_id=user_id_to_update, tenant_id=tenant_id)}
|
||||
return {"data": user}
|
||||
|
||||
|
||||
|
|
@ -423,7 +423,7 @@ async def delete_member(user_id, tenant_id, id_to_delete):
|
|||
change_pwd_expire_at= NULL, change_pwd_token= NULL
|
||||
WHERE user_id=%(user_id)s;""",
|
||||
{"user_id": id_to_delete}))
|
||||
return {"data": get_members(tenant_id=tenant_id)}
|
||||
return {"data": await get_members(tenant_id=tenant_id)}
|
||||
|
||||
|
||||
async def change_password(tenant_id, user_id, email, old_password, new_password):
|
||||
|
|
@ -453,7 +453,7 @@ async def set_password_invitation(user_id, new_password):
|
|||
r["limits"] = {
|
||||
"teamMember": -1,
|
||||
"projects": -1,
|
||||
"metadata": metadata.get_remaining_metadata_with_count(tenant_id)}
|
||||
"metadata": await metadata.get_remaining_metadata_with_count(tenant_id)}
|
||||
|
||||
c = await tenants.get_by_tenant_id(tenant_id)
|
||||
c.pop("createdAt")
|
||||
|
|
@ -689,7 +689,7 @@ async def update_user_module(user_id, data: schemas.ModuleStatus):
|
|||
# if module property is not exists, it will be created
|
||||
# if module property exists, it will be updated, modify here and call update_user_settings
|
||||
# module is a single element to be added or removed
|
||||
settings = get_user_settings(user_id)["settings"]
|
||||
settings = (await get_user_settings(user_id))["settings"]
|
||||
if settings is None:
|
||||
settings = {}
|
||||
|
||||
|
|
@ -702,7 +702,7 @@ async def update_user_module(user_id, data: schemas.ModuleStatus):
|
|||
elif not data.status and data.module in settings["modules"]:
|
||||
settings["modules"].remove(data.module)
|
||||
|
||||
return update_user_settings(user_id, settings)
|
||||
return await update_user_settings(user_id, settings)
|
||||
|
||||
|
||||
async def update_user_settings(user_id, settings):
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def __replace_images(HTML):
|
|||
return HTML, mime_img
|
||||
|
||||
|
||||
def send_html(BODY_HTML, SUBJECT, recipient, bcc=None):
|
||||
async def send_html(BODY_HTML, SUBJECT, recipient, bcc=None):
|
||||
BODY_HTML, mime_img = __replace_images(BODY_HTML)
|
||||
if not isinstance(recipient, list):
|
||||
recipient = [recipient]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue