Skip to content
GitHubBlueskydev.toRSS

07Distributed task execution

Run one task on a different machine

Give end-to-end tests machines of their own, while every other task shares the usual ones.

exec: {
command: 'playwright test',
worker: 'e2e',
}
Read
exec.worker@demo/ui#build@demo/web#build@demo/web#e2elinux.cpu4first typee2e.cpu4its own typeexec.worker@demo/ui#build@demo/web#build@demo/web#e2elinux.cpu4first typee2e.cpu4its own type
A task that names a worker type runs only there; the rest take the first type.

Add e2e next to linux. Order matters: a task that names no type goes to the first one with a machine of its platform.

.vx/workspace.ts
dte({
workers: {
linux: {
machines: {
cpu4: {
max: 8,
cpu: 4,
memory: '8GB',
},
},
},
e2e: {
machines: {
cpu4: {
max: 2,
cpu: 4,
memory: '8GB',
},
},
},
},
adapter: github(),
}),

You can now keep a separate pool of machines for one kind of work.

packages/web/vx.config.ts
e2e: {
dependsOn: ['build'],
exec: {
command: 'playwright test',
worker: 'e2e',
},
inputs: { files: ['src/**', 'tests/**'] },
},

Run vx lock, then vx dte init to add the new machines to vx-worker.yml. Now run it:

Terminal window
Tasks status cache ±usual time cpu mem outputs blocks worker task
success miss +1ms 16ms 24% 1.8MB 3B 2 linux.cpu4#1 @demo/ui#build
success miss +0ms 3ms 141% 1.8MB 3B 1 linux.cpu4#1 @demo/web#build
success miss +1ms 19ms 5% 1.7MB 0B 0 e2e.cpu4#1 @demo/web#e2e
workers e2e.cpu4#1 stopped 1 done · warm-up 0.2s · @demo/web#e2e
linux.cpu4#1 left 2 done · warm-up 0.1s · @demo/ui#build, @demo/web#build

Read the worker column: both builds ran on linux.cpu4#1, the tests on e2e.cpu4#1. Each worker left when its work was done.

Check yourself You add a lint task with no exec.worker. Which machines run it?

linux: it is listed first and runs on the same platform. e2e only gets tasks that name it.

You can now send one task to its own machines and see it land there.

PatternsCommon setups

Each type can run on different CI runners, with their own images and tools:

.vx/workspace.ts
workers: {
// runsOn: a self-hosted runner label of yours
alpine: {
machines: {
cpu4: {
max: 8,
cpu: 4,
memory: '16GB',
runsOn: 'alpine-4-cores',
},
},
},
ubuntu: {
machines: {
cpu4: {
max: 2,
cpu: 4,
memory: '16GB',
},
},
},
},
packages/web/vx.config.ts
e2e: { exec: { command: 'playwright test', worker: 'ubuntu' } },

A type listed later gets the tasks no type before it can run, such as tasks for macOS:

workers: {
linux: {
machines: {
cpu4: {
max: 8,
cpu: 4,
memory: '16GB',
},
},
},
mac: {
machines: {
m1: {
max: 2,
cpu: 3,
memory: '7GB',
platform: 'darwin-arm64',
},
},
},
},

A task with exec.platforms: ['darwin-arm64'] runs on mac. Every other task runs on linux.

You can now split work by tools or by platform with nothing but types and their order.

DetailsEvery rule
Fact exec.worker
What it does Runs the task only on machines of that worker type.
Default none: the first type in workers that fits the task.
Value a type’s name from dte({ workers }).
In the cache key no: moving a task to another type never changes its key.
On your machine ignored: a run without workers runs it here.
  • A task that names no type goes to the first type with a machine of its platform.
  • A task with exec.platforms runs only on a worker of one of them.
  • A task no worker can take stops the run before any task starts, and names it.
  • A task that reads what an uncached task leaves on its worker, where exec.worker or exec.platforms rule out the reader’s machine, stops the run too. Cache the upstream task, or run both alike.
NextGive heavy tasks a bigger machine →

Let vx pick the size each task needs.

Turborepo, Nx and other product names are trademarks of their owners. vx is not affiliated with or endorsed by them.