Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Temporal Workflow Patterns

Temporal Workflow Patterns

Master Temporal workflow orchestration for Google Antigravity IDE distributed systems

TemporalWorkflowsDistributed SystemsTypeScript
by Antigravity AI
⭐0Stars
.antigravity
# Temporal Workflow Patterns for Google Antigravity IDE

Build reliable distributed systems with Temporal using Google Antigravity IDE. This comprehensive guide covers workflow design, activities, signals, queries, and saga patterns for complex business processes.

## Workflow Definition

```typescript
// src/workflows/order-processing.ts
import { proxyActivities, sleep, condition, defineSignal, defineQuery, setHandler } from "@temporalio/workflow";
import type * as activities from "../activities";

const { 
  validateOrder, 
  reserveInventory, 
  processPayment, 
  shipOrder, 
  sendNotification,
  releaseInventory,
  refundPayment,
} = proxyActivities<typeof activities>({
  startToCloseTimeout: "1 minute",
  retry: {
    maximumAttempts: 3,
    initialInterval: "1 second",
    backoffCoefficient: 2,
    maximumInterval: "30 seconds",
  },
});

// Signals for external events
export const cancelOrderSignal = defineSignal<[string]>("cancelOrder");
export const updateShippingSignal = defineSignal<[ShippingInfo]>("updateShipping");

// Queries for workflow state
export const getOrderStatusQuery = defineQuery<OrderStatus>("getOrderStatus");

interface OrderInput {
  orderId: string;
  userId: string;
  items: OrderItem[];
  shippingInfo: ShippingInfo;
}

interface OrderStatus {
  stage: "validating" | "reserving" | "processing_payment" | "shipping" | "completed" | "cancelled" | "failed";
  timestamp: Date;
  error?: string;
}

export async function orderProcessingWorkflow(input: OrderInput): Promise<OrderResult> {
  let status: OrderStatus = { stage: "validating", timestamp: new Date() };
  let cancelled = false;
  let cancellationReason = "";
  let shippingInfo = input.shippingInfo;
  const compensations: Array<() => Promise<void>> = [];

  // Set up signal handlers
  setHandler(cancelOrderSignal, (reason: string) => {
    cancelled = true;
    cancellationReason = reason;
  });

  setHandler(updateShippingSignal, (newShipping: ShippingInfo) => {
    shippingInfo = newShipping;
  });

  // Set up query handlers
  setHandler(getOrderStatusQuery, () => status);

  try {
    // Stage 1: Validate order
    status = { stage: "validating", timestamp: new Date() };
    const validation = await validateOrder(input.orderId, input.items);
    if (!validation.valid) {
      throw new Error(`Validation failed: ${validation.reason}`);
    }

    // Check for cancellation
    if (cancelled) {
      throw new CancellationError(cancellationReason);
    }

    // Stage 2: Reserve inventory
    status = { stage: "reserving", timestamp: new Date() };
    const reservation = await reserveInventory(input.orderId, input.items);
    compensations.push(async () => {
      await releaseInventory(input.orderId, reservation.reservationId);
    });

    if (cancelled) {
      throw new CancellationError(cancellationReason);
    }

    // Stage 3: Process payment
    status = { stage: "processing_payment", timestamp: new Date() };
    const payment = await processPayment(input.orderId, input.userId, reservation.total);
    compensations.push(async () => {
      await refundPayment(payment.paymentId);
    });

    if (cancelled) {
      throw new CancellationError(cancellationReason);
    }

    // Stage 4: Ship order
    status = { stage: "shipping", timestamp: new Date() };
    const shipment = await shipOrder(input.orderId, shippingInfo);

    // Stage 5: Send confirmation
    await sendNotification(input.userId, "order_shipped", {
      orderId: input.orderId,
      trackingNumber: shipment.trackingNumber,
    });

    status = { stage: "completed", timestamp: new Date() };

    return {
      success: true,
      orderId: input.orderId,
      trackingNumber: shipment.trackingNumber,
    };
  } catch (error) {
    // Execute compensations in reverse order (saga pattern)
    status = { 
      stage: cancelled ? "cancelled" : "failed", 
      timestamp: new Date(),
      error: error instanceof Error ? error.message : "Unknown error",
    };

    for (const compensation of compensations.reverse()) {
      try {
        await compensation();
      } catch (compError) {
        console.error("Compensation failed:", compError);
      }
    }

    throw error;
  }
}
```

## Activities Implementation

```typescript
// src/activities/index.ts
import { ApplicationFailure } from "@temporalio/activity";
import { db } from "@/lib/db";
import { stripe } from "@/lib/stripe";
import { inventoryService } from "@/services/inventory";

export async function validateOrder(
  orderId: string, 
  items: OrderItem[]
): Promise<{ valid: boolean; reason?: string }> {
  // Validate items exist and are available
  for (const item of items) {
    const product = await db.product.findUnique({
      where: { id: item.productId },
    });

    if (!product) {
      return { valid: false, reason: `Product ${item.productId} not found` };
    }

    if (!product.active) {
      return { valid: false, reason: `Product ${product.name} is no longer available` };
    }

    if (item.quantity > product.maxQuantity) {
      return { valid: false, reason: `Quantity exceeds maximum for ${product.name}` };
    }
  }

  return { valid: true };
}

export async function reserveInventory(
  orderId: string,
  items: OrderItem[]
): Promise<{ reservationId: string; total: number }> {
  const reservation = await inventoryService.reserve({
    orderId,
    items,
    expiresIn: 15 * 60 * 1000, // 15 minutes
  });

  if (!reservation.success) {
    throw ApplicationFailure.nonRetryable(
      `Inventory reservation failed: ${reservation.reason}`,
      "INVENTORY_UNAVAILABLE"
    );
  }

  return {
    reservationId: reservation.id,
    total: reservation.total,
  };
}

export async function processPayment(
  orderId: string,
  userId: string,
  amount: number
): Promise<{ paymentId: string }> {
  const user = await db.user.findUnique({ where: { id: userId } });
  
  if (!user?.stripeCustomerId) {
    throw ApplicationFailure.nonRetryable(
      "User has no payment method",
      "NO_PAYMENT_METHOD"
    );
  }

  try {
    const paymentIntent = await stripe.paymentIntents.create({
      amount: Math.round(amount * 100),
      currency: "usd",
      customer: user.stripeCustomerId,
      confirm: true,
      off_session: true,
      metadata: { orderId },
    });

    return { paymentId: paymentIntent.id };
  } catch (error: any) {
    if (error.code === "card_declined") {
      throw ApplicationFailure.nonRetryable(
        "Payment declined",
        "PAYMENT_DECLINED"
      );
    }
    throw error;
  }
}
```

## Client Usage

```typescript
// src/services/order-client.ts
import { Client, Connection } from "@temporalio/client";
import { orderProcessingWorkflow, cancelOrderSignal, getOrderStatusQuery } from "@/workflows/order-processing";

const connection = await Connection.connect({ address: process.env.TEMPORAL_ADDRESS });
const client = new Client({ connection, namespace: "default" });

export async function startOrder(input: OrderInput) {
  const handle = await client.workflow.start(orderProcessingWorkflow, {
    taskQueue: "orders",
    workflowId: `order-${input.orderId}`,
    args: [input],
  });

  return { workflowId: handle.workflowId };
}

export async function cancelOrder(orderId: string, reason: string) {
  const handle = client.workflow.getHandle(`order-${orderId}`);
  await handle.signal(cancelOrderSignal, reason);
}

export async function getOrderStatus(orderId: string) {
  const handle = client.workflow.getHandle(`order-${orderId}`);
  return await handle.query(getOrderStatusQuery);
}
```

## Best Practices for Google Antigravity IDE

When using Temporal with Google Antigravity, design workflows to be deterministic. Use activities for non-deterministic operations. Implement compensation logic for saga patterns. Use signals for external events. Use queries for workflow state. Let Gemini 3 generate workflow definitions from business requirements.

Google Antigravity excels at modeling complex business processes as Temporal workflows.

When to Use This Prompt

This Temporal prompt is ideal for developers working on:

  • Temporal applications requiring modern best practices and optimal performance
  • Projects that need production-ready Temporal code with proper error handling
  • Teams looking to standardize their temporal development workflow
  • Developers wanting to learn industry-standard Temporal patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their temporal implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the Temporal code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this Temporal prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For Temporal projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...