Skip to content

Commit 2993b4a

Browse files
committed
fix: notifier state get's never persisted in database
- ever time the notification starts, it reports a corrupted state because the state never gets stored in the databse. saving the state in the database using `UPDATE` sql only works when there is already one entry in the table, otherwise the query will run through with zero updated rows. so in the case when the state cannot be loaded, we properly create one record inside the notifier_state table
1 parent 57e2ce4 commit 2993b4a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/oncall/notifier/reminder.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ def reminder(config):
4848
cursor.execute('SELECT `last_window_end` FROM `notifier_state`')
4949
if cursor.rowcount != 1:
5050
window_start = int(time.time() - interval)
51-
logger.warning('Corrupted/missing notifier state; unable to determine last window. Guessing %s',
51+
logger.warning('Corrupted/missing notifier state; unable to determine last window. Guessing %s. Creating state in database',
5252
window_start)
53+
# create a clean state in the datebase
54+
cursor.execute('DELETE FROM `notifier_state`')
55+
cursor.execute('INSERT INTO `notifier_state` (`last_window_end`) VALUES (%s) ', window_start)
56+
connection.commit()
5357
else:
5458
window_start = cursor.fetchone()[0]
5559

0 commit comments

Comments
 (0)