Пример #1
0
async def test_queue():
    queue = get_queue()
    item = 100500

    await queue.put(item)

    assert await queue.size() == 1
    assert await queue.pop() == item
    assert await queue.size() == 0
Пример #2
0
async def test_create_task():
    cache = get_cache()
    queue = get_queue()

    assert await queue.size() == 0

    task_uuid = await handler(f"create_task reversed_string abcd")
    task = Task.from_json(await cache.get(task_uuid))

    assert task.command == "reversed_string abcd"
    assert task.status == Status.QUEUE.value
    assert task.uuid == task_uuid
    assert await queue.size() == 1
    await queue.pop()
Пример #3
0
import asyncio

from server.queue import get_queue
from server.command import command_items
from server.task import Task
from server.status import Status
from server.cache import get_cache

cache = get_cache()
queue = get_queue()


def worker():
    return asyncio.run(_worker())


async def _worker():
    while True:
        if await queue.size() == 0:
            continue

        item = await queue.pop()
        task = Task.from_json(item)
        task.status = Status.IN_PROGRESS.value
        await cache.add(task.uuid, task.as_json())

        command, *args = task.command.split()
        func = command_items[command]
        got = await func(*args)

        task.status = Status.COMPLETED.value
Пример #4
0
async def test_singelton():
    queue = get_queue()

    assert queue is get_queue()