mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 22:25:35 +00:00
Add SIGTERM handling in sendreports
This commit is contained in:
parent
bc2d127c27
commit
1299738f50
3 changed files with 35 additions and 16 deletions
|
@ -9,7 +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
|
||||
- Add SIGTERM handling in sendalerts and sendreports
|
||||
|
||||
### Bug Fixes
|
||||
- Fix hc.api.views.ping to handle non-utf8 data in request body (#574)
|
||||
|
|
|
@ -139,7 +139,7 @@ class Command(BaseCommand):
|
|||
return True
|
||||
|
||||
def on_sigterm(self, *args):
|
||||
self.stdout.write("received SIGTERM, finishing...\n")
|
||||
self.stdout.write("Received SIGTERM, finishing...\n")
|
||||
self.sigterm = True
|
||||
|
||||
def handle(self, use_threads=True, loop=True, *args, **options):
|
||||
|
@ -148,22 +148,27 @@ class Command(BaseCommand):
|
|||
|
||||
self.stdout.write("sendalerts is now running\n")
|
||||
i, sent = 0, 0
|
||||
while True:
|
||||
while not self.sigterm:
|
||||
# Create flips for any checks going down
|
||||
while self.handle_going_down() and not self.sigterm:
|
||||
while not self.sigterm and self.handle_going_down():
|
||||
pass
|
||||
|
||||
# Process the unprocessed flips
|
||||
while self.process_one_flip(use_threads) and not self.sigterm:
|
||||
while not self.sigterm and self.process_one_flip(use_threads):
|
||||
sent += 1
|
||||
|
||||
if not loop or self.sigterm:
|
||||
if not loop:
|
||||
break
|
||||
|
||||
time.sleep(2)
|
||||
i += 1
|
||||
# Sleep for 2 seconds before looking for more work
|
||||
if not self.sigterm:
|
||||
i += 2
|
||||
time.sleep(2)
|
||||
|
||||
# Print "-- MARK --" approx. every minute so the logs
|
||||
# have evidence sendalerts is still running:
|
||||
if i % 60 == 0:
|
||||
timestamp = timezone.now().isoformat()
|
||||
self.stdout.write("-- MARK %s --\n" % timestamp)
|
||||
|
||||
return "Sent %d alert(s)" % sent
|
||||
return f"Sent {sent} alert(s)."
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import signal
|
||||
import time
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
@ -90,22 +91,35 @@ class Command(BaseCommand):
|
|||
|
||||
return True
|
||||
|
||||
def handle(self, *args, **options):
|
||||
def on_sigterm(self, *args):
|
||||
self.stdout.write("Received SIGTERM, finishing...\n")
|
||||
self.sigterm = True
|
||||
|
||||
def handle(self, loop=False, *args, **options):
|
||||
self.sigterm = False
|
||||
signal.signal(signal.SIGTERM, self.on_sigterm)
|
||||
|
||||
self.stdout.write("sendreports is now running")
|
||||
while True:
|
||||
while not self.sigterm:
|
||||
# Monthly reports
|
||||
while self.handle_one_report():
|
||||
while not self.sigterm and self.handle_one_report():
|
||||
pass
|
||||
|
||||
# Daily and hourly nags
|
||||
while self.handle_one_nag():
|
||||
while not self.sigterm and self.handle_one_nag():
|
||||
pass
|
||||
|
||||
if not options["loop"]:
|
||||
if not loop:
|
||||
break
|
||||
|
||||
# Sleep for 60 seconds before looking for more work
|
||||
for i in range(0, 60):
|
||||
if not self.sigterm:
|
||||
time.sleep(1)
|
||||
|
||||
# Print "-- MARK --" approx. every minute so the logs
|
||||
# have evidence sendreports is still running:
|
||||
formatted = timezone.now().isoformat()
|
||||
self.stdout.write("-- MARK %s --" % formatted)
|
||||
|
||||
# Sleep for 1 minute before looking for more work
|
||||
time.sleep(60)
|
||||
return "Done."
|
||||
|
|
Loading…
Add table
Reference in a new issue