aaaaaaarghhhhhhhh

This commit is contained in:
Jan-Ole Hübner 2024-08-18 00:21:28 +02:00
parent 877cda9640
commit 9fa7581574
2 changed files with 4 additions and 23 deletions

View file

@ -1,22 +1,8 @@
async def periodic_task():
while True:
try:
# Fetch price info and write to InfluxDB
p = Price(home.current_subscription.price_info.current).get_datapoint()
write_api.write(record=p, bucket=BUCKET)
logger.info(vars(p))
except Exception as e:
logger.exception("Error in periodic_task():")
# Wait for the next run (e.g., every 60 seconds)
await asyncio.sleep(3)
import asyncio import asyncio
import os import os
import signal import signal
import sys import sys
import time
import tibber import tibber
from influxdb_client import InfluxDBClient from influxdb_client import InfluxDBClient
@ -41,7 +27,7 @@ logger.setLevel(logging.INFO)
__version__ = "v0.3.4" __version__ = "v0.3.4"
logger.info(__version__) logger.info(__version__)
loop = asyncio.get_event_loop()
logger.info("connecting to db...") logger.info("connecting to db...")
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG) client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
@ -76,9 +62,6 @@ try:
signal.signal(signal.SIGALRM, timeout_handler) signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(15) signal.alarm(15)
home.start_live_feed(user_agent="pulse.py/0.3.4",exit_condition=stop(home),retries=2,retry_interval=3.0) home.start_live_feed(user_agent="pulse.py/0.3.4",exit_condition=stop(home),retries=2,retry_interval=3.0)
periodic_task_task = loop.create_task(periodic_task())
# Wait for both tasks to complete
except TypeError: except TypeError:
logger.exception("Timeout occurred while executing start_live_feed()") logger.exception("Timeout occurred while executing start_live_feed()")
client.close() client.close()
@ -93,5 +76,3 @@ except Exception:

View file

@ -5,8 +5,8 @@ python3 /app/pulse.py &
# Run the other script periodically in the background # Run the other script periodically in the background
( (
while true; do while true; do
python3 /app/get_price.py >> /var/log/other_script.log 2>&1 python3 /app/get_price.py
sleep 3 # Sleep for 60 seconds (1 minute) sleep 900
done done
) & ) &