Skip to main content

Distribute Task Execution (DTE)

Lerna (via Nx) supports running commands across multiple machines. You can either set it up by hand (by using batching or binning) or use Nx Cloud.

Read the comparison of the two approaches.

Set up

To distribute your task execution, you need to (1) connect to Nx Cloud and (2) enable DTE in your CI workflow. Each of these steps can be enabled with a single command:

1. Connect to Nx Cloud
nx connect-to-nx-cloud
2. Enable DTE in CI
nx generate @nrwl/workspace:ci-workflow --ci=github

The --ci flag can be github, circleci or azure. For more details on setting up DTE, read this guide.

CI Execution Flow

There are two main parts to the CI set up:

  1. The main job that controls what is going to be executed
  2. The agent jobs that actually execute the tasks

The main job execution flow looks like this:

    # Coordinate the agents to run the tasks
- npx nx-cloud start-ci-run
# Run any commands you want here
- nx affected --target=lint
- nx affected --target=test
- nx affected --target=build
# Stop any run away agents
- npx nx-cloud stop-all-agents

The agent job execution flow is very simple:

    # Wait for tasks to execute
- npx nx-cloud start-agent

Illustrated Guide

For more details about how distributed task execution works, check out the illustrated guide by Nrwlian Nicole Oliver.

how does distributed task execution work in Nx Cloud?