# Path: virtool/dispatcher/operations.py
# INSERT: Operation = "insert"
# UPDATE: Operation = "update"
# DELETE: Operation = "delete"


import asyncio
import json
from asyncio import CancelledError
from typing import Sequence, Union
from aioredis import Redis
from virtool.dispatcher.operations import Operation




class DispatcherClient:
    def __init__(self, redis: Redis):
        self._redis = redis
        self._q = asyncio.Queue()

    async def run(self):
        """
        Run the dispatcher.

        Continually publishes enqueued changes to a Redis channel.

        """
        try:
            while True:
                json_string = await self._q.get()
                await self._redis.publish("channel:dispatch", json_string)
        except CancelledError:
            pass

    def enqueue_change(

# Path: virtool/dispatcher/operations.py
# INSERT: Operation = "insert"
# UPDATE: Operation = "update"
# DELETE: Operation = "delete"


# Path: virtool/dispatcher/client.py
import asyncio
import json
from asyncio import CancelledError
from typing import Sequence, Union
from aioredis import Redis
from virtool.dispatcher.operations import Operation





class DispatcherClient:
    def __init__(self, redis: Redis):
        self._redis = redis
        self._q = asyncio.Queue()

    async def run(self):
        """
        Run the dispatcher.

        Continually publishes enqueued changes to a Redis channel.

        """
        try:
            while True:
                json_string = await self._q.get()
                await self._redis.publish("channel:dispatch", json_string)
        except CancelledError:
            pass

    def enqueue_change(

        self, interface: str, operation: Operation, id_list: Sequence[Union[str, int]]