mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 07:26:18 -05:00
Disabling all perpetual signals during testing, except switch_worker.
This commit is contained in:
parent
1f030daf75
commit
5820b86480
2 changed files with 9 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import multiprocessing
|
||||
import sys
|
||||
from asyncio import CancelledError
|
||||
from datetime import datetime, timezone, date
|
||||
from decimal import Decimal
|
||||
|
|
@ -13,6 +15,7 @@ from sanic import response, HTTPResponse, Request, Sanic, SanicException
|
|||
|
||||
from wrolpi.common import Base, get_media_directory, logger, LOGGING_CONFIG, TRACE_LEVEL
|
||||
from wrolpi.errors import APIError
|
||||
from wrolpi.vars import PYTEST
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
||||
|
|
@ -141,11 +144,15 @@ async def start_perpetual_tasks(app: Sanic):
|
|||
logger.debug('start_perpetual_tasks completed')
|
||||
|
||||
|
||||
def perpetual_signal(event: str = None, sleep: int | float = 1):
|
||||
def perpetual_signal(event: str = None, sleep: int | float = 1, run_while_testing: bool = False):
|
||||
"""Use Sanic signals to continually call the wrapped function. The wrapped function will continually be called,
|
||||
even if it has errors. If the function is long-running, it will only be called again after it has finished."""
|
||||
|
||||
def wrapper(func: callable):
|
||||
if PYTEST and not run_while_testing:
|
||||
# Do not run perpetual signal worker while testing, unless explicitly required.
|
||||
return func
|
||||
|
||||
# Create a Sanic "signal" for the provided function.
|
||||
event_ = event or f'wrolpi.perpetual.{func.__name__}'
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ def register_switch_handler(switch_name: str):
|
|||
DEBUG_LOGGED = False
|
||||
|
||||
|
||||
@perpetual_signal(sleep=0.1)
|
||||
@perpetual_signal(sleep=0.1, run_while_testing=True)
|
||||
async def switch_worker():
|
||||
"""Watches `api_app.shared_ctx.switches` for new activated switches, handles each one at a time."""
|
||||
global DEBUG_LOGGED
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue