
# Solve on another machine

You hand full solves to a machine faster than your server, a workstation on the network or a rented machine, without moving the application. Nothing below is mandatory: **without these variables, everything solves on site, as always**. The decision is in [ADR 0086](repo:docs/decisions/0086-le-calcul-deporte-un-worker-sans-conteneur-et-un-crochet.md), from which [ADR 0103](repo:docs/decisions/0103-retrait-du-lanceur-de-machine-a-la-demande.md) removes the on-demand machine.

## 1. Choose the formula

| Your situation | What you need |
| --- | --- |
| Everything on the same machine | nothing |
| A powerful workstation always on on the network | a **permanent worker**: `SOLVER_WORKER_URL` |
| A rented machine you switch on when needed with your host's tools | the same permanent worker; when it is off, a solve started "on the compute machine" fails with its reason, and "On site" stays available |
| The application rented, the solve at your place behind a router | **not served** as is: the application must be able to reach the worker, you need a tunnel or a VPN on your side |

Every connection **starts from the application**: the worker never calls back. Only the full solve leaves; partial rescheduling, diagnosis and the staffing check stay on site. What leaves your server, and to whom: [the remote solve](securite-appels-sortants.md#calcul-déporté--ce-qui-sort-et-vers-qui).

## 2. Install a permanent worker

It is **the same image**, started with `SOLVER_WORKER_MODE=true`: another program, which opens no database or mail and keeps nothing on disk. It needs the **same version** as the application: it refuses a problem from another one. On the compute machine, create a certificate, its fingerprint and the worker:

```bash
# A certificate for the worker, and its fingerprint for the application
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
  -keyout key.pem -out crt.pem -days 3650 -subj "/CN=solve-worker"
MDP="$(openssl rand -hex 16)"
openssl pkcs12 -export -inkey key.pem -in crt.pem -out worker.p12 -passout "pass:$MDP"
openssl x509 -in crt.pem -noout -fingerprint -sha256     # → SOLVER_WORKER_TLS_FINGERPRINT

docker run -d --name solve-worker --restart unless-stopped -p 8443:8443 \
  -e SOLVER_WORKER_MODE=true \
  -e SOLVER_WORKER_SECRET="$(openssl rand -hex 32)" \
  -e SOLVER_WORKER_TLS_KEYSTORE=/worker/worker.p12 \
  -e SOLVER_WORKER_TLS_KEYSTORE_PASSWORD="$MDP" \
  -v "$PWD/worker.p12:/worker/worker.p12:ro" \
  ghcr.io/sylvainmetayer/planning-equipes:<version>
```

Note the generated secret: the application must present the same. The worker takes three quarters of its machine's memory (`JDK_JAVA_OPTIONS`); 2 GB are enough for a usual edition.

| Worker variable | Default | Role |
| --- | --- | --- |
| `SOLVER_WORKER_MODE` | `false` | `true` starts the worker in place of the application |
| `SOLVER_WORKER_SECRET` | — | Mandatory: what the application must present |
| `SOLVER_WORKER_PORT` | `8443` | Listening port |
| `SOLVER_WORKER_TLS_KEYSTORE` | — | PKCS#12 file of the certificate. Without it, the worker speaks HTTP and listens on the loopback only: a development workstation, nothing else |
| `SOLVER_WORKER_TLS_KEYSTORE_PASSWORD` | empty | Password of that file |

## 3. Connect the application

In the application's `.env.prod`:

| Variable | Default | Role |
| --- | --- | --- |
| `SOLVER_WORKER_URL` | — | Address of the permanent worker, as `https://`. `http://` is only accepted towards the loopback |
| `SOLVER_WORKER_SECRET` | — | That worker's secret (mandatory with the address) |
| `SOLVER_WORKER_TLS_FINGERPRINT` | — | SHA-256 fingerprint of its certificate: only that one is then accepted, whatever its name. Empty: ordinary trust (a certificate signed by a recognised authority) |
| `SOLVER_WORKER_DEFAULT` | `local` | `remote`: a solve goes to the worker when its launch says nothing |

Once configured, the *Calculate* tab of the Planning page offers "On site" or "On the compute machine" at each launch.

## 4. Know what happens on a failure

- **A remote solve that fails fails the job**, with its reason and the end of the worker's log; nothing falls back on site. Start again choosing "On site", or retry. The saved plan is never touched by a failure.
- **The application may restart during a remote solve**: the worker carries on, and tracking resumes at the next start.
