make the mqtt feeder a timer since we're getting memory leaks or something

This commit is contained in:
Cyberes 2024-12-05 15:52:18 -07:00
parent 765f04978f
commit 86626495c2
5 changed files with 24 additions and 44 deletions

View File

@ -1,13 +1,12 @@
import gc
import logging
import numpy as np
import os
import paho.mqtt.client as mqtt
import pickle
import sys
import time
from datetime import datetime, timezone
import numpy as np
import paho.mqtt.client as mqtt
from dateutil.parser import parse
from redis import Redis
@ -56,8 +55,6 @@ def publish(topic: str, msg):
def main():
redis = Redis(host='localhost', port=6379, db=0)
while True:
data = redis.get('glotec')
while data is None:
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)
publish('glotec', latest)
del data
del geojson
del glotec_map_ranged
del avg_tec
del latest
gc.collect()
time.sleep(60)
if __name__ == '__main__':
main()

View File

@ -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

View File

@ -8,8 +8,7 @@ User=homeassistant
EnvironmentFile=/etc/secrets/space-weather
ExecStart=/srv/ha-noaa-space-weather/venv/bin/python /srv/ha-noaa-space-weather/feeder/cache.py
SyslogIdentifier=space-weather-cache
Restart=on-failure
RestartSec=5s
Restart=always
[Install]
WantedBy=multi-user.target

View File

@ -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
SyslogIdentifier=space-weather-mqtt
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,9 @@
[Unit]
Description=Space Weather MQTT timer
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target