Queue long-running backup and upload
This commit is contained in:
19
services/queue.py
Normal file
19
services/queue.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import asyncio
|
||||
from typing import Awaitable, Callable
|
||||
|
||||
|
||||
_queue: asyncio.Queue = asyncio.Queue()
|
||||
|
||||
|
||||
async def enqueue(job: Callable[[], Awaitable[None]]) -> int:
|
||||
await _queue.put(job)
|
||||
return _queue.qsize()
|
||||
|
||||
|
||||
async def worker():
|
||||
while True:
|
||||
job = await _queue.get()
|
||||
try:
|
||||
await job()
|
||||
finally:
|
||||
_queue.task_done()
|
||||
Reference in New Issue
Block a user