Skip to content

Commit

Permalink
add create event notifications for auto scheduler (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocepedaw committed Apr 4, 2023
1 parent 5873625 commit 86a3da7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/oncall/scheduler/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta
from pytz import timezone, utc
from oncall.utils import gen_link_id
from oncall.utils import gen_link_id, create_notification
from ..constants import EVENT_CREATED
from falcon import HTTPBadRequest
from ujson import dumps as json_dumps
import time
Expand Down Expand Up @@ -163,6 +164,19 @@ def create_events(self, team_id, schedule_id, user_id, events, role_id, cursor,
%%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
cursor.execute('SELECT `name` FROM `user` WHERE `id` = %s', user_id)
name = cursor.fetchone()
context = {
'team': team_id,
'role': role_id,
'full_name': name
}
create_notification(context, team_id,
[role_id],
EVENT_CREATED,
[user_id],
cursor,
start_time=event['start'])
else:
link_id = gen_link_id()
for event in events:
Expand All @@ -175,6 +189,19 @@ def create_events(self, team_id, schedule_id, user_id, events, role_id, cursor,
%%s, %%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
cursor.execute('SELECT `name` FROM `user` WHERE `id` = %s', user_id)
name = cursor.fetchone()
context = {
'team': team_id,
'role': role_id,
'full_name': name
}
create_notification(context, team_id,
[role_id],
EVENT_CREATED,
[user_id],
cursor,
start_time=event['start'])

def set_last_epoch(self, schedule_id, last_epoch, cursor):
cursor.execute('UPDATE `schedule` SET `last_epoch_scheduled` = %s WHERE `id` = %s',
Expand Down
29 changes: 28 additions & 1 deletion src/oncall/scheduler/round-robin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from oncall.utils import gen_link_id
from oncall.utils import gen_link_id, create_notification
from ..constants import EVENT_CREATED
from . import default
import logging

Expand Down Expand Up @@ -62,6 +63,19 @@ def create_events(self, team_id, schedule_id, user_id, events, role_id, cursor,
%%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
cursor.execute('SELECT `name` FROM `user` WHERE `id` = %s', user_id)
name = cursor.fetchone()
context = {
'team': team_id,
'role': role_id,
'full_name': name
}
create_notification(context, team_id,
[role_id],
EVENT_CREATED,
[user_id],
cursor,
start_time=event['start'])
else:
link_id = gen_link_id()
for event in events:
Expand All @@ -74,6 +88,19 @@ def create_events(self, team_id, schedule_id, user_id, events, role_id, cursor,
%%s, %%s, %%s, %%s, %%s, %%s, %%s
)''' % table_name
cursor.execute(query, event_args)
cursor.execute('SELECT `name` FROM `user` WHERE `id` = %s', user_id)
name = cursor.fetchone()
context = {
'team': team_id,
'role': role_id,
'full_name': name
}
create_notification(context, team_id,
[role_id],
EVENT_CREATED,
[user_id],
cursor,
start_time=event['start'])
cursor.execute('UPDATE `schedule` SET `last_scheduled_user_id` = %s WHERE `id` = %s', (user_id, schedule_id))

def populate(self, schedule, start_time, dbinfo, table_name='event'):
Expand Down

0 comments on commit 86a3da7

Please sign in to comment.