Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziosalmi authored Dec 16, 2024
1 parent 287f5a8 commit d28a1d0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def __init__(self, name: str, function: Callable, enabled: bool = True, timeout:
self.enabled = enabled
self.timeout = timeout

async def execute(self, website: str, default_timeout: int) -> str:
async def execute(self, website: str, config: Config, default_timeout: int) -> str:
"""Execute the check with timeout handling."""
try:
if asyncio.iscoroutinefunction(self.function):
return await asyncio.wait_for(self.function(website, api_key=self.config.pagespeed_api_key), self.timeout or default_timeout)
return self.function(website, api_key=self.config.pagespeed_api_key)
return await asyncio.wait_for(self.function(website, api_key=config.pagespeed_api_key), self.timeout or default_timeout)
return self.function(website, api_key=config.pagespeed_api_key)
except asyncio.TimeoutError:
logger.warning(f"Check {self.name} for {website} timed out.")
return "🔴" # Timeout indicator
Expand Down Expand Up @@ -199,7 +199,7 @@ async def main():
for check in monitor.check_functions:
results = []
for website in config.websites:
result = await check.execute(website, config.timeout)
result = await check.execute(website, config, config.timeout)
results.append(result)
check_results.append((check.name, results))

Expand Down

0 comments on commit d28a1d0

Please sign in to comment.