RFC: Sidecar Tasks #23273
Replies: 2 comments
-
Looking at our monorepo this would be useful as described! There are some more complex things that do need to have a concept of 'ready'. Codegen in watch mode is a common one. For example, we currently integrate GraphQL Codegen via a Vite plugin in dev mode since there's no clean way to do this outside of it right now. The node executor has waitUntilTargets that does something like this but is not super flexible (waits for any console output as far as I can tell). I'd like something like this, where the sidecars/targets can take some optional configuration to configure a wait for ready: {
name: "api",
targets: {
serve: {
command: "node ./server.js",
sidecars: [
"database:start",
{
target: "api:codegen:watch",
waitForOutput: /✔ Generate outputs/, // or just true to wait for any console output
waitTimeout: 10, // assume failure if the ready condition isn't met in time
},
],
},
},
} |
Beta Was this translation helpful? Give feedback.
-
Another example might be where you have a dev command that relies on other packages. i.e.
Having package3:dev Currently you could do this with |
Beta Was this translation helpful? Give feedback.
-
Problem
E2E tasks, dev-server tasks, and other kinds of tasks need a task to run alongside when they run. This problem is not solved by
dependsOn
because dependent tasks must complete before the task is run.Prior Art
https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/
Proposed Solution (not final)
Nx can have a notion of tasks which run alongside the task being run.
In this configuration, the
app-e2e:e2e
task would specify that it would likeapp:serve
to be running before it runs as well as while it is running. Runningnx e2e app-e2e
would execute the following chain of events:app-e2e:e2e
as well as anydependsOn
,sidecar
, and any dependent tasks ofsidecar
tasks.dependsOn
tasks.dependsOn
tasks are completed,sidecar
tasks are run WITHapp-e2e:e2e
This would also be considered for running multiple tasks. When running
nx run-many -t e2e
multiple e2e tasks could depend on the same web server. Nx could try to schedule this in a way where the sidecar task is started once and then multiple e2e tasks with the same sidecar task are run in parallel with the same sidecar task.Considerations
Starting dev servers and databases might not be instantaneous but also do not complete. At the same time, tasks do not currently have a notion of "ready". Tasks can be built in a way where they can be started without sidecar tasks being truly ready and handle when that sidecar is ready. I imagine most applications are already built like this as they would need this sort of functionality when running in production. Thus, I'm not sure if tasks need to introduce the notion of "ready" to enable sidecar tasks.
Examples
Starting a web-server to e2e test
Currently in Nx, the e2e task is responsible for starting the web-server which it is testing. With sidecars, this can be changed to Nx being responsible for starting the web server while the e2e task is responsible for waiting for the server to be ready. Cypress, Playwright and other e2e tasks runners already do this.
Starting backends alongside a web server
This would start the required backends while running a frontend application.
Starting a db alongside a backend server
Publishing to a local-registry before running e2e tests
Beta Was this translation helpful? Give feedback.
All reactions