Mercurial > code > home > repos > homeauto
diff service/powerEagle/reader.py @ 1719:fb082013fa24
port to use my background_loop lib. various other dep updates.
author | drewp@bigasterisk.com |
---|---|
date | Sat, 27 Aug 2022 18:31:46 -0700 |
parents | 4cbe3df8f48f |
children | bacb13c10c7a |
line wrap: on
line diff
--- a/service/powerEagle/reader.py Sun Aug 07 04:43:47 2022 -0700 +++ b/service/powerEagle/reader.py Sat Aug 27 18:31:46 2022 -0700 @@ -1,19 +1,18 @@ -import asyncio import binascii import json import logging from typing import Dict import aiohttp +import background_loop from patchablegraph import PatchableGraph from patchablegraph.handler import GraphEvents, StaticGraph -from prometheus_client import Gauge, Summary +from prometheus_client import Gauge from rdflib import Literal, Namespace from starlette.applications import Starlette from starlette.routing import Route from starlette_exporter import PrometheusMiddleware, handle_metrics -import background_loop from private_config import cloudId, deviceIp, installId, macId, periodSec ROOM = Namespace("http://projects.bigasterisk.com/room/") @@ -24,9 +23,6 @@ authPlain = cloudId + ':' + installId auth = binascii.b2a_base64(authPlain.encode('ascii')).strip(b'=\n') -STAT_UPDATE_UP = Gauge('background_loop_up', 'not erroring') -STAT_UPDATE_CALLS = Summary('background_loop_calls', 'calls') - class Poller(object): @@ -34,7 +30,7 @@ self.out = out self.graph = graph - async def poll(self, first: bool): + async def poll(self, first_run: bool): url = (f'http://{deviceIp}/cgi-bin/cgi_manager') async with aiohttp.ClientSession() as session: @@ -85,7 +81,7 @@ p = Poller(out, masterGraph) # todo: background_loop isn't trying to maintain a goal of periodSec - asyncio.create_task(background_loop.loop_forever(p.poll, periodSec, STAT_UPDATE_UP, STAT_UPDATE_CALLS)) + loop = background_loop.loop_forever(p.poll, periodSec) app = Starlette(debug=True, routes=[