Skip to content

Commit

Permalink
refactor: Swap ports of runner and launcher (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Nov 27, 2024
1 parent 1429429 commit a763510
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CLI utility to launch [n8n task runners](https://docs.n8n.io/PENDING).

### Install

- Install Node.js >=18.17
- Install Node.js >=18.17
- Install n8n >= PENDING_VERSION
- Download launcher binary from [releases page](https://github.com/n8n-io/task-runner-launcher/releases)

Expand All @@ -39,9 +39,7 @@ Sample config file:
"runner-type": "javascript",
"workdir": "/usr/local/bin",
"command": "/usr/local/bin/node",
"args": [
"/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/start.js"
],
"args": ["/usr/local/lib/node_modules/n8n/node_modules/@n8n/task-runner/dist/start.js"],
"allowed-env": [
"PATH",
"N8N_RUNNERS_GRANT_TOKEN",
Expand Down Expand Up @@ -75,15 +73,15 @@ To control the launcher's log level, set the `N8N_LAUNCHER_LOG_LEVEL` env var to

### Idle timeout

If idle for 15 seconds, the runner will exit. To override this duration, set the `N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT` to a number of seconds, or `0` to disable it. After runner exit on idle timeout, the launcher will re-launch the runner on demand, i.e. when the next task comes in.
If idle for 15 seconds, the runner will exit. To override this duration, set the `N8N_RUNNERS_AUTO_SHUTDOWN_TIMEOUT` to a number of seconds, or `0` to disable it. After runner exit on idle timeout, the launcher will re-launch the runner on demand, i.e. when the next task comes in.

## Usage

Once setup is complete, start the launcher:

```sh
export N8N_RUNNERS_AUTH_TOKEN=...
export N8N_RUNNERS_N8N_URI=...
export N8N_RUNNERS_N8N_URI=...
./task-runner-launcher javascript
```

Expand All @@ -106,7 +104,7 @@ sudo mv config.json /etc/n8n-task-runners.json

```sh
export N8N_RUNNERS_ENABLED=true
export N8N_RUNNERS_MODE=external
export N8N_RUNNERS_MODE=external
export N8N_RUNNERS_LAUNCHER_PATH=... # i.e. path/to/launcher/binary
export N8N_RUNNERS_AUTH_TOKEN=... # i.e. random string
pnpm start
Expand All @@ -123,9 +121,9 @@ make run

## Health check

The launcher exposes a health check endpoint at `/healthz` on port `5681` for liveness checks.
The launcher exposes a health check endpoint at `/healthz` on port `5680` for liveness checks.

To override the launcher health check port, set the `N8N_LAUNCHER_HEALTCHECK_PORT` env var. When overriding the default health check port, be mindful of port conflicts - the n8n main instance uses `5678` by default for its HTTP server and `5679` for its task runner server, and the runner uses `5680` by default for its healthcheck server.
To override the launcher health check port, set the `N8N_LAUNCHER_HEALTCHECK_PORT` env var. When overriding the default health check port, be mindful of port conflicts - the n8n main instance uses `5678` by default for its HTTP server and `5679` for its task runner server, and the runner uses `5681` by default for its healthcheck server.

## Release

Expand All @@ -138,5 +136,5 @@ git push origin v1.2.0

2. Publish a [GitHub release](https://github.com/n8n-io/task-runner-launcher/releases/new) with the tag. The [`release` workflow](./.github/workflows/release.yml) will build binaries for arm64 and amd64 and upload them to the release in the [releases page](https://github.com/n8n-io/task-runner-launcher/releases).

> [!IMPORTANT]
> Mark the GitHub release as `latest` and NOT as `pre-release` or the `release` workflow will not run.
> [!IMPORTANT]
> Mark the GitHub release as `latest` and NOT as `pre-release` or the `release` workflow will not run.
4 changes: 2 additions & 2 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
// ------------------------

// EnvVarRunnerServerURI is the env var for the URI of the runner's server.
// Used for monitoring the runner's health, typically at http://127.0.0.1:5680.
// Used for monitoring the runner's health, typically at http://127.0.0.1:5681.
EnvVarRunnerServerURI = "N8N_RUNNER_URI"

// EnvVarRunnerServerEnabled is the env var for whether the runner's health
Expand All @@ -57,7 +57,7 @@ const (
defaultIdleTimeoutValue = "15" // seconds
DefaultMainServerURI = "http://127.0.0.1:5678"
DefaultTaskBrokerServerURI = "http://127.0.0.1:5679"
DefaultRunnerServerURI = "http://127.0.0.1:5680"
DefaultRunnerServerURI = "http://127.0.0.1:5681"
)

// AllowedOnly filters the current environment down to only those
Expand Down
24 changes: 12 additions & 12 deletions internal/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestFromEnv(t *testing.T) {
envVars: map[string]string{
EnvVarMainServerURI: "http://localhost:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expectError: true,
},
Expand All @@ -181,7 +181,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://\\invalid:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expectError: true,
},
Expand All @@ -190,13 +190,13 @@ func TestFromEnv(t *testing.T) {
envVars: map[string]string{
EnvVarAuthToken: "token123",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expected: &EnvConfig{
AuthToken: "token123",
MainServerURI: DefaultMainServerURI,
TaskBrokerServerURI: "http://localhost:5679",
RunnerServerURI: "http://localhost:5680",
RunnerServerURI: "http://localhost:5681",
},
},
{
Expand All @@ -205,7 +205,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://localhost:5678",
EnvVarTaskBrokerServerURI: "http://\\invalid:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expectError: true,
},
Expand All @@ -214,13 +214,13 @@ func TestFromEnv(t *testing.T) {
envVars: map[string]string{
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://localhost:5678",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expected: &EnvConfig{
AuthToken: "token123",
MainServerURI: "http://localhost:5678",
TaskBrokerServerURI: DefaultTaskBrokerServerURI,
RunnerServerURI: "http://localhost:5680",
RunnerServerURI: "http://localhost:5681",
},
},
{
Expand All @@ -229,7 +229,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://localhost:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://\\invalid:5680",
EnvVarRunnerServerURI: "http://\\invalid:5681",
},
expectError: true,
},
Expand All @@ -253,7 +253,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "127.0.0.1:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expectError: true,
},
Expand All @@ -263,7 +263,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "localhost:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
},
expectError: true,
},
Expand All @@ -273,7 +273,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://localhost:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
EnvVarIdleTimeout: "invalid",
},
expectError: true,
Expand All @@ -284,7 +284,7 @@ func TestFromEnv(t *testing.T) {
EnvVarAuthToken: "token123",
EnvVarMainServerURI: "http://localhost:5678",
EnvVarTaskBrokerServerURI: "http://localhost:5679",
EnvVarRunnerServerURI: "http://localhost:5680",
EnvVarRunnerServerURI: "http://localhost:5681",
EnvVarIdleTimeout: "-1",
},
expectError: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/http/healthcheck_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

const (
defaultPort = 5681
defaultPort = 5680
portEnvVar = "N8N_LAUNCHER_HEALTCHECK_PORT"
healthCheckPath = "/healthz"
readTimeout = 1 * time.Second
Expand Down

0 comments on commit a763510

Please sign in to comment.