make the mqtt feeder a timer since we're getting memory leaks or something
This commit is contained in:
parent
765f04978f
commit
86626495c2
|
@ -1,13 +1,12 @@
|
||||||
import gc
|
import gc
|
||||||
import logging
|
import logging
|
||||||
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import paho.mqtt.client as mqtt
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
from redis import Redis
|
from redis import Redis
|
||||||
|
|
||||||
|
@ -56,8 +55,6 @@ def publish(topic: str, msg):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
redis = Redis(host='localhost', port=6379, db=0)
|
redis = Redis(host='localhost', port=6379, db=0)
|
||||||
|
|
||||||
while True:
|
|
||||||
data = redis.get('glotec')
|
data = redis.get('glotec')
|
||||||
while data is None:
|
while data is None:
|
||||||
logging.warning('Redis has not been populated yet. Is cache.py running? Sleeping 10s...')
|
logging.warning('Redis has not been populated yet. Is cache.py running? Sleeping 10s...')
|
||||||
|
@ -74,15 +71,6 @@ def main():
|
||||||
latest = round(avg_tec, 1)
|
latest = round(avg_tec, 1)
|
||||||
publish('glotec', latest)
|
publish('glotec', latest)
|
||||||
|
|
||||||
del data
|
|
||||||
del geojson
|
|
||||||
del glotec_map_ranged
|
|
||||||
del avg_tec
|
|
||||||
del latest
|
|
||||||
gc.collect()
|
|
||||||
|
|
||||||
time.sleep(60)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
SOURCE=${BASH_SOURCE[0]}
|
|
||||||
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
|
||||||
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
|
|
||||||
SOURCE=$(readlink "$SOURCE")
|
|
||||||
[[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
|
||||||
done
|
|
||||||
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
|
|
||||||
|
|
||||||
cp "$DIR"/*.service /etc/systemd/system
|
|
||||||
systemctl daemon-reload
|
|
||||||
systemctl enable --now *.service
|
|
||||||
systemctl restart *.service
|
|
||||||
systemctl status *.service
|
|
|
@ -8,8 +8,7 @@ User=homeassistant
|
||||||
EnvironmentFile=/etc/secrets/space-weather
|
EnvironmentFile=/etc/secrets/space-weather
|
||||||
ExecStart=/srv/ha-noaa-space-weather/venv/bin/python /srv/ha-noaa-space-weather/feeder/cache.py
|
ExecStart=/srv/ha-noaa-space-weather/venv/bin/python /srv/ha-noaa-space-weather/feeder/cache.py
|
||||||
SyslogIdentifier=space-weather-cache
|
SyslogIdentifier=space-weather-cache
|
||||||
Restart=on-failure
|
Restart=always
|
||||||
RestartSec=5s
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -9,7 +9,6 @@ EnvironmentFile=/etc/secrets/space-weather
|
||||||
ExecStart=/srv/ha-noaa-space-weather/venv/bin/python /srv/ha-noaa-space-weather/feeder/mqtt.py
|
ExecStart=/srv/ha-noaa-space-weather/venv/bin/python /srv/ha-noaa-space-weather/feeder/mqtt.py
|
||||||
SyslogIdentifier=space-weather-mqtt
|
SyslogIdentifier=space-weather-mqtt
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5s
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Space Weather MQTT timer
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=hourly
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
Loading…
Reference in New Issue