Skip to content

Commit

Permalink
fix: reset_user_data_usage job only for limited and active users
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Feb 20, 2024
1 parent 7adc25a commit 9c4b274
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/jobs/reset_user_data_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
def reset_user_data_usage():
now = datetime.utcnow()
with GetDB() as db:
for user in get_users(db, reset_strategy=[
UserDataLimitResetStrategy.day.value,
UserDataLimitResetStrategy.week.value,
UserDataLimitResetStrategy.month.value,
UserDataLimitResetStrategy.year.value,
]):
for user in get_users(db,
status=[
UserStatus.active,
UserStatus.limited
],
reset_strategy=[
UserDataLimitResetStrategy.day.value,
UserDataLimitResetStrategy.week.value,
UserDataLimitResetStrategy.month.value,
UserDataLimitResetStrategy.year.value,
]):
last_reset_time = user.last_traffic_reset_time
num_days_to_reset = reset_strategy_to_days[user.data_limit_reset_strategy]

Expand Down
5 changes: 4 additions & 1 deletion app/jobs/review_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

if TYPE_CHECKING:
from app.db.models import User
import time


def add_notification_reminders(db: Session, user: "User", now: datetime = datetime.utcnow()) -> None:
Expand All @@ -36,6 +37,8 @@ def add_notification_reminders(db: Session, user: "User", now: datetime = dateti


def review():
while True:
time.sleep(1)
now = datetime.utcnow()
now_ts = now.timestamp()
with GetDB() as db, GetBG() as bg:
Expand Down Expand Up @@ -90,4 +93,4 @@ def review():
logger.info(f"User \"{user.username}\" status changed to {status}")


scheduler.add_job(review, 'interval', seconds=5, coalesce=True, max_instances=1)
scheduler.add_job(review, 'interval', seconds=10, coalesce=True, max_instances=1)

0 comments on commit 9c4b274

Please sign in to comment.