Add active checking
This commit is contained in:
16
db.py
16
db.py
@@ -1,8 +1,13 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from sqlalchemy import create_engine, String, select, ForeignKey
|
||||
from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column, relationship
|
||||
|
||||
|
||||
def tow(day: int, hour: int, minute: int):
|
||||
return minute + hour * 60 + day * 60 * 24
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
@@ -46,6 +51,17 @@ class User(Base):
|
||||
'queue': [x.to_dict() for x in self.queue],
|
||||
}
|
||||
|
||||
def is_active_now(self):
|
||||
if not len(self.schedule):
|
||||
return True
|
||||
dt = datetime.now()
|
||||
curr_tow = tow(dt.weekday(), dt.hour, dt.minute)
|
||||
for x in self.schedule:
|
||||
if (tow(x.day_start, x.hour_start, x.minute_start) <= curr_tow
|
||||
<= tow(x.day_end, x.hour_end, x.minute_end)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Profile(Base):
|
||||
__tablename__ = 'profiles'
|
||||
|
||||
1
main.py
1
main.py
@@ -70,6 +70,7 @@ def replication_task():
|
||||
with (Session(conn) as session):
|
||||
for bndname in connected:
|
||||
for item in session.query(db.Queue).join(db.Queue.user).filter_by(bndname=bndname).all():
|
||||
if item.user.is_active_now():
|
||||
replication(bndname, item.commit_id, item.schema)
|
||||
session.delete(item)
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user