mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-04 02:48:12 +10:00
Merge pull request #202 from lowar/catch_sigterm
Add a SIGTERM handler to gracefully shutdown running app
This commit is contained in:
@@ -10,6 +10,7 @@ import sys
|
|||||||
import getopt
|
import getopt
|
||||||
import yaml
|
import yaml
|
||||||
import time
|
import time
|
||||||
|
import signal
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
configfilename = 'config.yaml'
|
configfilename = 'config.yaml'
|
||||||
@@ -145,6 +146,8 @@ def main():
|
|||||||
|
|
||||||
scan_interval = config_inverter.get('scan_interval')
|
scan_interval = config_inverter.get('scan_interval')
|
||||||
|
|
||||||
|
signal.signal(signal.SIGTERM, handle_sigterm)
|
||||||
|
|
||||||
# Core polling loop
|
# Core polling loop
|
||||||
while True:
|
while True:
|
||||||
loop_start = time.perf_counter()
|
loop_start = time.perf_counter()
|
||||||
@@ -181,6 +184,11 @@ def main():
|
|||||||
logging.info(f'Next scrape in {int(scan_interval - process_time)} secs')
|
logging.info(f'Next scrape in {int(scan_interval - process_time)} secs')
|
||||||
time.sleep(scan_interval - process_time)
|
time.sleep(scan_interval - process_time)
|
||||||
|
|
||||||
|
def handle_sigterm(signum, frame):
|
||||||
|
print("Received SIGTERM, shutting down gracefully...")
|
||||||
|
# Perform any cleanup here
|
||||||
|
exit(0)
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s %(levelname)-8s %(message)s',
|
format='%(asctime)s %(levelname)-8s %(message)s',
|
||||||
level=logging.DEBUG,
|
level=logging.DEBUG,
|
||||||
|
|||||||
Reference in New Issue
Block a user