0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/workflows
review a5df14de83 chore: merge main to refresh stream qualification baseline
Keep main's worker takeover tests and short fixture lease alongside the stream evidence job, then requalify against current stream-bus and recovery behavior.

Targeted tests, typechecks and lint passed. The repository pre-commit hook crashed in tsgolint on an unchanged upstream test file; bypassed for this merge.

Co-Authored-By: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
History 2026-11-16 08:06:33 -08:00
..
_test-utils fix(core): reset retryCount on each evented loop iteration (#30383) 2026-11-14 01:01:42 -03:00
inngest chore: merge main to refresh stream qualification baseline 2026-11-16 08:06:33 -08:00
temporal chore: version packages (alpha) (#30430) 2026-11-16 14:09:31 +01:00
oxlint.config.ts chore: migrate linting to oxlint (#20173) 2026-07-25 01:04:02 +02:00
README.md fix(docs): Fix Inngest example (#5500) 2025-07-01 09:43:13 -07:00

Inngest Workflow Engine

Run Mastra workflows with Inngest.

Workflow and step execution functionality is exposed via serve from @mastra/inngest. This is a wrapper that detects all Mastra workflows created to run with Inngest and registers them to the Inngest server.

Steps and workflows are created using the createStep and createWorkflow functions initialized with init() from @mastra/inngest. This makes sure that all the steps are ready and able to connect with the Inngets runtime, publish events for watching, etc.

The Inngest runtime is horizontally scalable, with watching and eventing working through the @inngest/realtime package.

Usage

Running inngest dev server

docker run --rm -p 8288:8288 \
  inngest/inngest \
  inngest dev -u http://host.docker.internal:4111/inngest/api

Example

import { init, serve as inngestServe } from '@mastra/inngest';
import { PinoLogger } from '@mastra/loggers';
import { Inngest } from 'inngest';
import { z } from 'zod';

const inngest = new Inngest({
  id: 'mastra',
  baseUrl: `http://localhost:8288`, // if using local dev server
});

const { createWorkflow, createStep } = init(inngest);

const incrementStep = createStep({
  id: 'increment',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    return { value: inputData.value + 1 };
  },
});

const sideEffectStep = createStep({
  id: 'side-effect',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    console.log('log', inputData.value);
    return { value: inputData.value };
  },
});

const finalStep = createStep({
  id: 'final',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
  execute: async ({ inputData }) => {
    return { value: inputData.value };
  },
});

const incrementWorkflow = createWorkflow({
  id: 'increment-workflow',
  inputSchema: z.object({
    value: z.number(),
  }),
  outputSchema: z.object({
    value: z.number(),
  }),
})
  .dountil(
    createWorkflow({
      id: 'increment-subworkflow',
      inputSchema: z.object({
        value: z.number(),
      }),
      outputSchema: z.object({
        value: z.number(),
      }),
      steps: [incrementStep, sideEffectStep],
    })
      .then(incrementStep)
      .then(sideEffectStep)
      .commit(),
    async ({ inputData }) => inputData.value >= 10,
  )
  .then(finalStep)
  .commit();

export const mastra = new Mastra({
  vnext_workflows: {
    incrementWorkflow,
  },
  server: {
    host: '0.0.0.0',
    apiRoutes: [
      {
        path: '/inngest/api', // this needs to match the path in inngest dev server (or production) config
        method: 'ALL',
        createHandler: async ({ mastra }) => inngestServe({ mastra, inngest }),
      },
    ],
  },
  logger: new PinoLogger({
    name: 'Mastra',
    level: 'info',
  }),
});