Skip to content

Commit

Permalink
fix: notifier state get's never persisted in database
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
roock committed Jun 3, 2022
1 parent 57e2ce4 commit 2993b4a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/oncall/notifier/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ def reminder(config):
cursor.execute('SELECT `last_window_end` FROM `notifier_state`')
if cursor.rowcount != 1:
window_start = int(time.time() - interval)
logger.warning('Corrupted/missing notifier state; unable to determine last window. Guessing %s',
logger.warning('Corrupted/missing notifier state; unable to determine last window. Guessing %s. Creating state in database',
window_start)
# create a clean state in the datebase
cursor.execute('DELETE FROM `notifier_state`')
cursor.execute('INSERT INTO `notifier_state` (`last_window_end`) VALUES (%s) ', window_start)
connection.commit()
else:
window_start = cursor.fetchone()[0]

Expand Down

0 comments on commit 2993b4a

Please sign in to comment.