# All files / src/trpc/routers dispatch.ts

9.09% Statements 1/11
100% Branches 0/0
20% Functions 1/5
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

    11x

     /**
     * Dispatch Router — queue, dispatchNext, getQueueState, completeTask
     */

    import { z } from 'zod';
    import type { ProcedureBuilder } from '../trpc.js';
    import { requireDispatchManager } from './_helpers.js';

    export function dispatchProcedures(publicProcedure: ProcedureBuilder) {
      return {
        queueTask: publicProcedure
          .input(z.object({ taskId: z.string().min(1) }))
          .mutation(async ({ ctx, input }) => {
            const dispatchManager = requireDispatchManager(ctx);
            await dispatchManager.queue(input.taskId);
            return { success: true };
          }),

        dispatchNext: publicProcedure
          .mutation(async ({ ctx }) => {
            const dispatchManager = requireDispatchManager(ctx);
            return dispatchManager.dispatchNext();
          }),

        getQueueState: publicProcedure
          .query(async ({ ctx }) => {
            const dispatchManager = requireDispatchManager(ctx);
            return dispatchManager.getQueueState();
          }),

        completeTask: publicProcedure
          .input(z.object({ taskId: z.string().min(1) }))
          .mutation(async ({ ctx, input }) => {
            const dispatchManager = requireDispatchManager(ctx);
            await dispatchManager.completeTask(input.taskId);
            return { success: true };
          }),
      };
    }