Browse Source

Add SIGTERM handling in sendalerts

master
Pēteris Caune 3 years ago
parent
commit
bc2d127c27
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 12 additions and 4 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +11
    -4
      hc/api/management/commands/sendalerts.py

+ 1
- 0
CHANGELOG.md View File

@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Implement automatic `api_ping` and `api_notification` pruning (#556)
- Update Dockerfile to install apprise (#581)
- Improve period and grace controls, allow up to 365 day periods (#281)
- Add SIGTERM handling in sendalerts
### Bug Fixes
- Fix hc.api.views.ping to handle non-utf8 data in request body (#574)


+ 11
- 4
hc/api/management/commands/sendalerts.py View File

@ -1,4 +1,5 @@
from datetime import timedelta as td
import signal
import time
from threading import Thread
@ -137,20 +138,26 @@ class Command(BaseCommand):
return True
def on_sigterm(self, *args):
self.stdout.write("received SIGTERM, finishing...\n")
self.sigterm = True
def handle(self, use_threads=True, loop=True, *args, **options):
self.stdout.write("sendalerts is now running\n")
self.sigterm = False
signal.signal(signal.SIGTERM, self.on_sigterm)
self.stdout.write("sendalerts is now running\n")
i, sent = 0, 0
while True:
# Create flips for any checks going down
while self.handle_going_down():
while self.handle_going_down() and not self.sigterm:
pass
# Process the unprocessed flips
while self.process_one_flip(use_threads):
while self.process_one_flip(use_threads) and not self.sigterm:
sent += 1
if not loop:
if not loop or self.sigterm:
break
time.sleep(2)


Loading…
Cancel
Save