# Source: https://upstash.com/docs/workflow/features/sleep.md

# Source: https://upstash.com/docs/workflow/basics/context/sleep.md

> ## Documentation Index
> Fetch the complete documentation index at: https://upstash.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# context.sleep

`context.sleep()` pauses workflow execution for a specified duration.

When a workflow is paused, the current request completes and a new one is automatically scheduled to resume after the delay.
This ensures no compute resources are consumed during the sleep period.

<Note>Always `await` a `sleep` step to properly pause execution.</Note>

## Arguments

<ParamField body="stepName" type="string">
  A unique identifier for the step.
</ParamField>

<ParamField body="duration" type="number|string">
  The duration to pause workflow execution.

  * **Human-readable string format:**

  | Input   | Duration   |
  | ------- | ---------- |
  | `"10s"` | 10 seconds |
  | `"1m"`  | 1 minute   |
  | `"30m"` | 30 minutes |
  | `"2h"`  | 2 hours    |
  | `"1d"`  | 1 day      |
  | `"1w"`  | 1 week     |
  | `"1mo"` | 1 month    |
  | `"1y"`  | 1 year     |

  * **Numeric format (seconds):**

  | Input   | Duration              |
  | ------- | --------------------- |
  | `60`    | 60 seconds (1 minute) |
  | `3600`  | 3600 seconds (1 hour) |
  | `86400` | 86400 seconds (1 day) |
</ParamField>

## Usage

<CodeGroup>
  ```typescript TypeScript highlight={12-13} theme={"system"}
  import { serve } from "@upstash/workflow/nextjs";
  import { signIn, sendEmail } from "@/utils/onboarding-utils";

  export const { POST } = serve<User>(async (context) => {
    const userData = context.requestPayload;

    const user = await context.run("sign-in", async () => {
      const signedInUser = await signIn(userData);
      return signedInUser;
    });

    // 👇 Wait for one day (in seconds)
    await context.sleep("wait-until-welcome-email", "1d");

    await context.run("send-welcome-email", async () => {
      return sendEmail(user.name, user.email);
    });
  });
  ```

  ```python Python theme={"system"}
  from fastapi import FastAPI
  from upstash_workflow.fastapi import Serve
  from upstash_workflow import AsyncWorkflowContext
  from onboarding_utils import sign_in, send_email

  app = FastAPI()
  serve = Serve(app)


  @serve.post("/api/onboarding")
  async def onboarding(context: AsyncWorkflowContext[User]) -> None:
      user_data = context.request_payload

      async def _sign_in():
          return await sign_in(user_data)

      user = await context.run("sign-in", _sign_in)

      # 👇 Wait for one day (in seconds)
      await context.sleep("wait-until-welcome-email", "1d")

      async def _send_email():
          return await send_email(user.name, user.email)

      await context.run("send-welcome-email", _send_email)

  ```
</CodeGroup>