Skip to content

Commit

Permalink
feat: map order checks
Browse files Browse the repository at this point in the history
  • Loading branch information
harsxv committed Sep 6, 2024
1 parent d3a1ab9 commit 90ace49
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tinystatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ async def check_port(host, port):
return False

async def run_checks(checks):
background_tasks = set()
task = None
background_tasks = {}
async with asyncio.TaskGroup() as tg:
for check in checks:
if check['type'] == 'http':
Expand All @@ -61,11 +60,13 @@ async def run_checks(checks):
task = tg.create_task(check_port(check['host'], check['port']), name=check['name'])

if task:
background_tasks.add(task)
background_tasks[check['name']] = task

results = [
{"name": check["name"], "status": background_tasks[check["name"]].result()}
for check in checks
]

results = []
for task in background_tasks:
results.append({'name': task.get_name(), 'status': task.result()})
return results

# History management
Expand Down Expand Up @@ -106,7 +107,7 @@ async def monitor_services():
history_template = Template(f.read())

results = await run_checks(checks)
print(results)

update_history(results)

html = template.render(checks=results, incidents=incidents, last_updated=datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Expand Down Expand Up @@ -146,4 +147,4 @@ def main():

if __name__ == "__main__":
logging.basicConfig(level=getattr(logging, LOG_LEVEL), format='%(asctime)s - %(levelname)s - %(message)s')
asyncio.run(monitor_services())
asyncio.run(monitor_services())

0 comments on commit 90ace49

Please sign in to comment.