-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,42 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from ..config import Config | ||
from ..database import query | ||
from ..database.models import ScheduledCallQueue | ||
from ..database.connection import get_session | ||
|
||
|
||
def build_queue() -> None: | ||
pass | ||
|
||
now = datetime.now() | ||
office_hours = Config.get().telephony.office_hours | ||
if not office_hours.open(now): | ||
return | ||
|
||
with get_session() as session: | ||
timeframe = timedelta(minutes=office_hours.call_schedule_interval) | ||
calls = query.get_currently_scheduled_calls(session, now, timeframe) | ||
# we want to sort and preserve this order in sqlalchemy's session.add | ||
# so we iterate it. | ||
calls.sort(key=lambda call: call.start_time) | ||
for call in calls: | ||
session.add( | ||
ScheduledCallQueue( | ||
user_id=call.user_id, | ||
language=call.language, | ||
)) | ||
query.mark_scheduled_calls_queued(session, calls, now) | ||
session.commit() | ||
|
||
|
||
def handle_queue() -> None: | ||
pass | ||
|
||
now = datetime.now() | ||
with get_session() as session: | ||
queued_call = query.get_currently_queued_call(session, now) | ||
if queued_call is None: | ||
return | ||
# TODO Start call | ||
# query.get_random_destination(session) | ||
session.delete(queued_call) | ||
session.commit() |