Skip to content

Commit

Permalink
Fix bugs (#1503)
Browse files Browse the repository at this point in the history
* fix(jobs): not record usages

* fix(webhook): notify user onhold is actvated
  • Loading branch information
ImMohammad20000 authored Dec 11, 2024
1 parent 17e1cdb commit dab0cdb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions app/jobs/record_usages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from typing import Union

from pymysql.err import OperationalError
from sqlalchemy import and_, bindparam, insert, select, sql, update
from sqlalchemy import and_, bindparam, insert, select, update
from sqlalchemy.orm import Session
from sqlalchemy.sql.dml import Insert

from app import scheduler, xray
from app.db import GetDB
Expand All @@ -19,16 +21,16 @@
from xray_api import exc as xray_exc


def safe_execute(db, stmt, params=None):
def safe_execute(db: Session, stmt, params=None):
if db.bind.name == 'mysql':
if isinstance(stmt, sql.dml.Insert):
if isinstance(stmt, Insert):
stmt = stmt.prefix_with('IGNORE')

tries = 0
done = False
while not done:
try:
db.execute(stmt, params)
db.connection().execute(stmt, params, execution_options={"synchronize_session": None})
db.commit()
done = True
except OperationalError as err:
Expand All @@ -39,7 +41,7 @@ def safe_execute(db, stmt, params=None):
raise err

else:
db.execute(stmt, params)
db.connection().execute(stmt, params, execution_options={"synchronize_session": None})
db.commit()


Expand Down
4 changes: 2 additions & 2 deletions app/utils/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ class UserExpired(UserNotification):

class UserEnabled(UserNotification):
action: Notification.Type = Notification.Type.user_enabled
by: Admin = None
by: Admin | None = None
user: UserResponse


class UserDisabled(UserNotification):
action: Notification.Type = Notification.Type.user_disabled
by: Admin
user: UserResponse
reason: str = None
reason: str | None = None


class UserDataUsageReset(UserNotification):
Expand Down

0 comments on commit dab0cdb

Please sign in to comment.