You've already forked oncall
mirror of
https://github.com/linkedin/oncall.git
synced 2025-11-29 23:38:17 +02:00
add create event notifications for auto scheduler (#392)
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pytz import timezone, utc
|
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 falcon import HTTPBadRequest
|
||||||
from ujson import dumps as json_dumps
|
from ujson import dumps as json_dumps
|
||||||
import time
|
import time
|
||||||
@@ -163,6 +164,19 @@ class Scheduler(object):
|
|||||||
%%s, %%s, %%s, %%s, %%s, %%s
|
%%s, %%s, %%s, %%s, %%s, %%s
|
||||||
)''' % table_name
|
)''' % table_name
|
||||||
cursor.execute(query, event_args)
|
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:
|
else:
|
||||||
link_id = gen_link_id()
|
link_id = gen_link_id()
|
||||||
for event in events:
|
for event in events:
|
||||||
@@ -175,6 +189,19 @@ class Scheduler(object):
|
|||||||
%%s, %%s, %%s, %%s, %%s, %%s, %%s
|
%%s, %%s, %%s, %%s, %%s, %%s, %%s
|
||||||
)''' % table_name
|
)''' % table_name
|
||||||
cursor.execute(query, event_args)
|
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):
|
def set_last_epoch(self, schedule_id, last_epoch, cursor):
|
||||||
cursor.execute('UPDATE `schedule` SET `last_epoch_scheduled` = %s WHERE `id` = %s',
|
cursor.execute('UPDATE `schedule` SET `last_epoch_scheduled` = %s WHERE `id` = %s',
|
||||||
|
|||||||
@@ -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
|
from . import default
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -62,6 +63,19 @@ class Scheduler(default.Scheduler):
|
|||||||
%%s, %%s, %%s, %%s, %%s, %%s
|
%%s, %%s, %%s, %%s, %%s, %%s
|
||||||
)''' % table_name
|
)''' % table_name
|
||||||
cursor.execute(query, event_args)
|
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:
|
else:
|
||||||
link_id = gen_link_id()
|
link_id = gen_link_id()
|
||||||
for event in events:
|
for event in events:
|
||||||
@@ -74,6 +88,19 @@ class Scheduler(default.Scheduler):
|
|||||||
%%s, %%s, %%s, %%s, %%s, %%s, %%s
|
%%s, %%s, %%s, %%s, %%s, %%s, %%s
|
||||||
)''' % table_name
|
)''' % table_name
|
||||||
cursor.execute(query, event_args)
|
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))
|
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'):
|
def populate(self, schedule, start_time, dbinfo, table_name='event'):
|
||||||
|
|||||||
Reference in New Issue
Block a user