(
        self, *, event: WebhookEvent, first: bool
    )
return find_position((key for key, value in kvs), event.json())
1. get the corresponding repo queue for event
        2. add key to MERGE_QUEUE_NAMES so on restart we can recreate the
        worker for the queue.
        3. add event
        4. start worker (will create new worker if one does not exist)

        returns position of event in queue
1. get the corresponding repo queue for event
        2. add key to MERGE_QUEUE_NAMES so on restart we can recreate the
        worker for the queue.
        3. add event
        4. start worker (will create new worker if one does not exist)
1 . get the corresponding repo queue for event 2 . add key to MERGE_QUEUE_NAMES so on restart we can recreate the worker for the queue . 3 . add event 4 . start worker ( will create new worker if one does not exist )
async def enqueue_for_repo(
        self, *, event: WebhookEvent, first: bool
    ) -> Optional[int]:
        """
        1. get the corresponding repo queue for event
        2. add key to MERGE_QUEUE_NAMES so on restart we can recreate the
        worker for the queue.
        3. add event
        4. start worker (will create new worker if one does not exist)

        returns position of event in queue
        """
        queue_name = get_merge_queue_name(event)
        transaction = await self.connection.multi()
        merge_queues_by_install = f"merge_queue_by_install:{event.installation_id}"
        await transaction.sadd(merge_queues_by_install, [queue_name])
        await transaction.expire(merge_queues_by_install, seconds=ONE_DAY)
        if first:
            # place at front of queue. To allow us to always place this PR at
            # the front, we should not pass only_if_not_exists.
            await transaction.zadd(queue_name, {event.json(): 1.0})
        else:
            # use only_if_not_exists to prevent changing queue positions on new
            # webhook events.
            await transaction.zadd(
                queue_name, {event.json(): time.time()}, only_if_not_exists=True
            )
        future_results = await transaction.zrange(queue_name, 0, 1000)
        await transaction.exec()
        log = logger.bind(
            owner=event.repo_owner,
            repo=event.repo_name,
            number=event.pull_request_number,
            install=event.installation_id,
        )

        log.info("enqueue repo event")
        self.start_repo_worker(queue_name=queue_name)
        results = await future_results
        dictionary = await results.asdict()
        kvs = sorted(
            ((key, value) for key, value in dictionary.items()), key=lambda x: x[1]
        )
        return find_position((key for key, value in kvs), event.json())
async def enqueue_for_repo ( self , * , event : WebhookEvent , first : bool ) -> Optional [ int ] : queue_name = get_merge_queue_name ( event ) transaction = await self . connection . multi ( ) merge_queues_by_install = f"merge_queue_by_install:{event.installation_id}" await transaction . sadd ( merge_queues_by_install , [ queue_name ] ) await transaction . expire ( merge_queues_by_install , seconds = ONE_DAY ) if first : # place at front of queue. To allow us to always place this PR at # the front, we should not pass only_if_not_exists. await transaction . zadd ( queue_name , { event . json ( ) : 1.0 } ) else : # use only_if_not_exists to prevent changing queue positions on new # webhook events. await transaction . zadd ( queue_name , { event . json ( ) : time . time ( ) } , only_if_not_exists = True ) future_results = await transaction . zrange ( queue_name , 0 , 1000 ) await transaction . exec ( ) log = logger . bind ( owner = event . repo_owner , repo = event . repo_name , number = event . pull_request_number , install = event . installation_id , ) log . info ( "enqueue repo event" ) self . start_repo_worker ( queue_name = queue_name ) results = await future_results dictionary = await results . asdict ( ) kvs = sorted ( ( ( key , value ) for key , value in dictionary . items ( ) ) , key = lambda x : x [ 1 ] ) return find_position ( ( key for key , value in kvs ) , event . json ( ) )