File size: 726 Bytes
5c1df24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Batch two telemetry writes before dispatching an agent."""
import asyncio
from guardshift import Index


async def worker(inbox):
    event = await inbox.get()
    print("batch worker received", event)


async def main():
    # Start the batch worker when queue depth >= 100 and GPU usage <= 70%.
    guards = [[(0, 100, 2**63 - 1), (1, 0, 70)]]
    index = Index([95, 60], guards)
    inbox = asyncio.Queue()
    task = asyncio.create_task(worker(inbox))

    for patch in [[(0, 101), (1, 85)], [(1, 65)]]:
        for guard_id, active in index.apply(patch):
            if active:
                await inbox.put({"guard_id": guard_id, "patch": patch})
    await task


if __name__ == "__main__":
    asyncio.run(main())