Skip to content

Commit a04c9b9

Browse files
committed
Remove the stop() method
1 parent 7ab6383 commit a04c9b9

File tree

3 files changed

+5
-13
lines changed

3 files changed

+5
-13
lines changed

mqlog/__init__.mpy

-88 Bytes
Binary file not shown.

mqlog/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,16 @@ def __init__(
3737
self.capacity = capacity
3838
self.buffer = []
3939
self.will_flush = asyncio.Event()
40-
self.active = True
4140

4241
async def run(self):
4342
"""
4443
Continuously publish log records via MQTT.
4544
This method should be scheduled as an asyncio task.
4645
"""
47-
self.active = True
48-
while self.active:
46+
while True:
4947
await self.will_flush.wait()
5048
await self._flush()
5149

52-
def stop(self):
53-
"""Stop the handler from processing further log records."""
54-
self.active = False
55-
5650
# Check if we should publish an MQTT message
5751
def _should_flush(self, record):
5852
return (len(self.buffer) >= self.capacity) or (

tests/test_handler.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ def test_publish(self):
4848
"""Flushing should publish messages to MQTT topic"""
4949
self.handler.flush_level = logging.ERROR
5050

51-
async def do_test(handler, logger):
51+
async def do_test(logger):
5252
logger.info("Test message 1")
5353
await asyncio.sleep(0.1)
5454
logger.error("Test message 2")
5555
await asyncio.sleep(0.1)
56-
handler.stop()
5756

5857
async def main(handler, logger):
59-
await asyncio.gather(handler.run(), do_test(handler, logger))
58+
await asyncio.gather(handler.run(), do_test(logger))
6059

6160
asyncio.run(main(self.handler, self.logger))
6261

@@ -68,7 +67,7 @@ def test_flush_multiple(self):
6867
"""Flushing multiple times should publish separate messages"""
6968
self.handler.capacity = 2
7069

71-
async def do_test(handler, logger):
70+
async def do_test(logger):
7271
logger.info("Test message 1")
7372
await asyncio.sleep(0.1)
7473
logger.info("Test message 2")
@@ -77,10 +76,9 @@ async def do_test(handler, logger):
7776
await asyncio.sleep(0.1)
7877
logger.info("Test message 4")
7978
await asyncio.sleep(0.1)
80-
handler.stop()
8179

8280
async def main(handler, logger):
83-
await asyncio.gather(handler.run(), do_test(handler, logger))
81+
await asyncio.gather(handler.run(), do_test(logger))
8482

8583
asyncio.run(main(self.handler, self.logger))
8684

0 commit comments

Comments
 (0)