Run the job tracker as its own container at /jobs/
Test and deploy / test (push) Successful in 2m3s
Test and deploy / deploy (push) Successful in 1m31s

The tracker (applications, leads, email pipeline, capture userscript) now
lives in the adamf/job-tracker repo and runs here from its published image.

- docker-compose.yml: a `jobs` service with an explicit environment list
  (its own database role; none of the site's other secrets), ./jobs-data
  mounted at /data, and nginx waiting for it. The dev override seeds it.
- nginx: /jobs/ proxied to it with the prefix kept, and 301s from
  /cv/jobs, /cv/leads and the old userscript URL.
- env_registry.json and .env.example: the email and job-lead variables now
  belong to the jobs service; CLAUDE_* to python and jobs; new
  POSTGRES_JOBS_* and JOBS_IMAGE_TAG. The compose environment test now
  checks the jobs service's list as well as python's.
- backend: no longer starts the email and job-lead schedulers or serves
  the capture and email routes, since the tracker reads the same settings
  and would otherwise process everything twice. The old job code stays
  until the tracker has run for a while.
- vue: the CV page's Jobs button goes to /jobs/; the old routes are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 17:08:18 +01:00
co-authored by Claude Opus 5.5
parent 148b94959d
commit 931b02c9e4
12 changed files with 208 additions and 102 deletions
+9 -18
View File
@@ -1,7 +1,6 @@
package main
import (
"context"
"fmt"
"io"
"log"
@@ -203,12 +202,11 @@ func main() {
protected := r.Group("/", store.AuthMiddlewear)
admin := r.Group("/", store.AuthMiddlewear, store.AdminMiddleware)
// JOB CAPTURE: called by the browser userscript from other origins, so
// these authenticate with a bearer token instead of the session cookies.
capture := r.Group("/jobs/capture", store.CaptureTokenMiddleware)
capture.GET("/status", store.JobCaptureStatus)
capture.POST("/extract", store.JobCaptureExtract)
capture.POST("", store.JobCapture)
// JOB CAPTURE and EMAIL SYNC routes moved to the job tracker app
// (adamf/job-tracker, served at /jobs/). They are no longer registered
// here, so an old userscript gets a 404 instead of writing into tables
// the tracker no longer reads. The handlers are deleted in a later
// commit, once the tracker has run for a while.
// ROWING
r.GET("/rowing", store.GetRowing)
@@ -221,10 +219,6 @@ func main() {
r.POST("/auth/logout", store.Logout)
r.GET("/auth/validate-admin", store.ValidateAdmin)
// EMAIL SYNC
r.GET("/email/callback", store.CompleteEmailAuth)
admin.POST("/email/sync", store.TriggerEmailSync)
// SPOTIFY
// The callback must be open — Spotify redirects a logged-out browser to
// it — and is protected by the state nonce instead. Starting the flow is
@@ -314,13 +308,10 @@ func main() {
c.JSON(200, gin.H{"message": "Hello World"})
})
// The scheduler runs until ctx is cancelled, which in practice only
// happens if r.Run returns — there is no signal handling or graceful
// shutdown, so the container is simply killed.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go store.EmailSync.StartScheduler(ctx)
go store.JobLeads.StartScheduler(ctx)
// The email sync and job-lead schedulers are NOT started: the job tracker
// runs them now, and it reads the same EMAIL_SYNC_ENABLED and
// JOB_LEADS_ENABLED from .env, so starting them here as well would
// process every email and board twice.
port := os.Getenv("BACKEND_PORT")
// Blocks until the server stops. Any return is a failure — a port clash,
+42 -34
View File
@@ -63,16 +63,16 @@ func TestEnvRegistryMatchesEnvExample(t *testing.T) {
}
}
// composePythonEnv returns the variable names in the `environment:` list of
// the `python` service in docker-compose.yml.
// composeServiceEnv returns the variable names in the `environment:` list of
// one service in docker-compose.yml.
//
// It reads the file as text rather than through a YAML library — there is
// none among this module's direct dependencies, and the shape needed is
// narrow: a two-space-indented `python:` key under `services:`, a
// narrow: a two-space-indented `<service>:` key under `services:`, a
// four-space-indented `environment:` under it, and `- NAME=value` items. If
// the compose file is ever restructured so that this finds nothing, the test
// below fails loudly rather than passing on an empty list.
func composePythonEnv(t *testing.T) []string {
func composeServiceEnv(t *testing.T, service string) []string {
t.Helper()
raw, err := os.ReadFile("../../docker-compose.yml")
if err != nil {
@@ -81,7 +81,7 @@ func composePythonEnv(t *testing.T) []string {
item := regexp.MustCompile(`^ - ["']?([A-Z][A-Z0-9_]*)(=|["']?\s*$)`)
var names []string
inPython, inEnvironment := false, false
inService, inEnvironment := false, false
for _, line := range strings.Split(string(raw), "\n") {
trimmed := strings.TrimSpace(line)
if trimmed == "" || strings.HasPrefix(trimmed, "#") {
@@ -91,61 +91,69 @@ func composePythonEnv(t *testing.T) []string {
switch {
case indent <= 2:
// A new service (or a top-level key) ends the block.
inPython, inEnvironment = line == " python:", false
case inPython && indent == 4:
inService, inEnvironment = line == " "+service+":", false
case inService && indent == 4:
inEnvironment = trimmed == "environment:"
case inPython && inEnvironment:
case inService && inEnvironment:
match := item.FindStringSubmatch(line)
if match == nil {
t.Fatalf("python.environment has an entry this test cannot read: %q", line)
t.Fatalf("%s.environment has an entry this test cannot read: %q", service, line)
}
names = append(names, match[1])
}
}
if len(names) == 0 {
t.Fatal("found no python.environment list in docker-compose.yml; has the file's layout changed?")
t.Fatalf("found no %s.environment list in docker-compose.yml; has the file's layout changed?", service)
}
return names
}
// The python service is the one container given an explicit `environment:`
// list instead of the whole .env, so that it never holds the database
// password or the JWT secret. The cost is a third place a new Python variable
// has to be added — the registry, .env.example and that list — and forgetting
// the third is silent: the variable is simply empty inside the container.
//
// So the registry's claim "python reads this" and the compose list must
// explicitEnvServices are the containers given an explicit `environment:`
// list instead of the whole .env, so that they never hold the database
// password or the JWT secret: the Python service, and the job tracker (an
// image from its own repo, which gets its own database role besides). The
// cost is a third place a new variable for one of them has to be added — the
// registry, .env.example and that list — and forgetting the third is silent:
// the variable is simply empty inside the container.
var explicitEnvServices = []string{"python", "jobs"}
// So the registry's claim "this service reads this" and the compose list must
// agree, in both directions:
//
// - a variable the registry says python reads must be passed to it;
// - a variable the registry says the service reads must be passed to it;
// - an editable variable that is passed to it must say so in the registry,
// or changing it in the admin panel would not recreate the container.
//
// Locked variables are exempt from the second rule. They are never applied
// through the panel, so the registry gives none of them a services list
// (PYTHON_PORT is passed to python and is one of these). Names in the compose
// list that are not registry variables at all, such as the literal ROOT_PATH,
// are not this test's business.
func TestEnvRegistryMatchesComposePythonEnvironment(t *testing.T) {
compose := composePythonEnv(t)
// list that are not registry variables at all, such as the literal ROOT_PATH
// or the jobs service's composed DATABASE_URL, are not this test's business.
func TestEnvRegistryMatchesComposeEnvironments(t *testing.T) {
registry := map[string]EnvVar{}
for _, v := range newEnvManager(t).Vars() {
registry[v.Name] = v
if slices.Contains(v.Services, "python") && !slices.Contains(compose, v.Name) {
t.Errorf("%s lists the python service in env_registry.json but is not in "+
"python.environment in docker-compose.yml, so the container never receives it", v.Name)
}
}
for _, name := range compose {
v, known := registry[name]
if !known || !v.Editable {
continue
for _, service := range explicitEnvServices {
compose := composeServiceEnv(t, service)
for _, v := range registry {
if slices.Contains(v.Services, service) && !slices.Contains(compose, v.Name) {
t.Errorf("%s lists the %s service in env_registry.json but is not in "+
"%s.environment in docker-compose.yml, so the container never receives it", v.Name, service, service)
}
}
if !slices.Contains(v.Services, "python") {
t.Errorf("%s is passed to the python service in docker-compose.yml but env_registry.json "+
"does not list python among its services, so editing it would not recreate the container", name)
for _, name := range compose {
v, known := registry[name]
if !known || !v.Editable {
continue
}
if !slices.Contains(v.Services, service) {
t.Errorf("%s is passed to the %s service in docker-compose.yml but env_registry.json "+
"does not list %s among its services, so editing it would not recreate the container", name, service, service)
}
}
}
}
+22 -18
View File
@@ -1,6 +1,6 @@
[
{"name": "CLAUDE_API_KEY", "group": "API keys", "purpose": "Claude calls, all made by the Python service: email classifier, rowing photo reader, job posting reader, job lead scorer", "kind": "secret", "editable": true, "services": ["python"], "docsUrl": "https://console.anthropic.com/settings/keys"},
{"name": "CLAUDE_MODEL", "group": "API keys", "purpose": "Model for every Claude call: lead scoring, email classifier, posting reader, rowing photo reader. Blank uses claude-sonnet-5-5. Rough cost per million tokens in/out: Haiku $1/$5, Sonnet $2/$10, Opus $4/$20", "kind": "enum", "options": ["claude-haiku-4-5", "claude-sonnet-5-5", "claude-opus-5-5"], "editable": true, "services": ["python"]},
{"name": "CLAUDE_API_KEY", "group": "API keys", "purpose": "Claude calls: the job tracker (lead scorer, email classifier, posting reader) and the Python service (rowing photo reader)", "kind": "secret", "editable": true, "services": ["python", "jobs"], "docsUrl": "https://console.anthropic.com/settings/keys"},
{"name": "CLAUDE_MODEL", "group": "API keys", "purpose": "Model for every Claude call: lead scoring, email classifier, posting reader (job tracker), rowing photo reader (Python). Blank uses claude-sonnet-5-5. Rough cost per million tokens in/out: Haiku $1/$5, Sonnet $2/$10, Opus $4/$20", "kind": "enum", "options": ["claude-haiku-4-5", "claude-sonnet-5-5", "claude-opus-5-5"], "editable": true, "services": ["python", "jobs"]},
{"name": "STEAM_API_KEY", "group": "API keys", "purpose": "Steam status widget", "kind": "secret", "editable": true, "services": ["backend"], "docsUrl": "https://steamcommunity.com/dev/apikey"},
{"name": "STEAM_ID", "group": "API keys", "purpose": "Steam account the widget reports on (64-bit ID)", "kind": "text", "editable": true, "services": ["backend"]},
{"name": "TFL_APP_KEY", "group": "API keys", "purpose": "TfL Unified API, used by the hotel finder", "kind": "secret", "editable": true, "services": ["python"], "docsUrl": "https://api-portal.tfl.gov.uk/profile"},
@@ -10,23 +10,23 @@
{"name": "SPOTIFY_REDIRECT_URI", "group": "Spotify", "purpose": "Must match the URI registered in the Spotify dashboard exactly", "kind": "url", "editable": true, "services": ["backend"]},
{"name": "SPOTIFY_AUTH_STATE", "group": "Spotify", "purpose": "Former fixed OAuth state", "kind": "secret", "editable": false, "lockedReason": "No longer read: the OAuth state is a per-request nonce."},
{"name": "EMAIL_BACKEND", "group": "Email ingest", "purpose": "Mail source for the email pipeline", "kind": "enum", "options": ["graph", "imap"], "editable": true, "services": ["backend"]},
{"name": "EMAIL_SYNC_ENABLED", "group": "Email ingest", "purpose": "Run the periodic email sync", "kind": "bool", "editable": true, "services": ["backend"]},
{"name": "EMAIL_SYNC_INTERVAL", "group": "Email ingest", "purpose": "Time between syncs, as a Go duration such as 30m (default 30m)", "kind": "duration", "editable": true, "services": ["backend"]},
{"name": "MSGRAPH_CLIENT_ID", "group": "Email ingest", "purpose": "Microsoft Graph app registration", "kind": "text", "editable": true, "services": ["backend"], "docsUrl": "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade"},
{"name": "MSGRAPH_CLIENT_SECRET", "group": "Email ingest", "purpose": "Microsoft Graph app registration", "kind": "secret", "editable": true, "services": ["backend"], "docsUrl": "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade"},
{"name": "MSGRAPH_TENANT_ID", "group": "Email ingest", "purpose": "\"consumers\" for a personal outlook.com account", "kind": "text", "editable": true, "services": ["backend"]},
{"name": "MSGRAPH_REDIRECT_URI", "group": "Email ingest", "purpose": "OAuth callback, behind the site's HTTPS origin", "kind": "url", "editable": true, "services": ["backend"]},
{"name": "IMAP_HOST", "group": "Email ingest", "purpose": "IMAP fallback server", "kind": "text", "editable": true, "services": ["backend"]},
{"name": "IMAP_PORT", "group": "Email ingest", "purpose": "IMAP fallback port (993)", "kind": "number", "editable": true, "services": ["backend"]},
{"name": "IMAP_EMAIL", "group": "Email ingest", "purpose": "IMAP fallback account", "kind": "text", "editable": true, "services": ["backend"]},
{"name": "IMAP_PASSWORD", "group": "Email ingest", "purpose": "App-specific password, not the account password", "kind": "secret", "editable": true, "services": ["backend"]},
{"name": "EMAIL_BACKEND", "group": "Email ingest", "purpose": "Mail source for the email pipeline", "kind": "enum", "options": ["graph", "imap"], "editable": true, "services": ["jobs"]},
{"name": "EMAIL_SYNC_ENABLED", "group": "Email ingest", "purpose": "Run the periodic email sync", "kind": "bool", "editable": true, "services": ["jobs"]},
{"name": "EMAIL_SYNC_INTERVAL", "group": "Email ingest", "purpose": "Time between syncs, as a Go duration such as 30m (default 30m)", "kind": "duration", "editable": true, "services": ["jobs"]},
{"name": "MSGRAPH_CLIENT_ID", "group": "Email ingest", "purpose": "Microsoft Graph app registration", "kind": "text", "editable": true, "services": ["jobs"], "docsUrl": "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade"},
{"name": "MSGRAPH_CLIENT_SECRET", "group": "Email ingest", "purpose": "Microsoft Graph app registration", "kind": "secret", "editable": true, "services": ["jobs"], "docsUrl": "https://entra.microsoft.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade"},
{"name": "MSGRAPH_TENANT_ID", "group": "Email ingest", "purpose": "\"consumers\" for a personal outlook.com account", "kind": "text", "editable": true, "services": ["jobs"]},
{"name": "MSGRAPH_REDIRECT_URI", "group": "Email ingest", "purpose": "OAuth callback: https://<domain>/jobs/api/email/callback, registered in Entra", "kind": "url", "editable": true, "services": ["jobs"]},
{"name": "IMAP_HOST", "group": "Email ingest", "purpose": "IMAP fallback server", "kind": "text", "editable": true, "services": ["jobs"]},
{"name": "IMAP_PORT", "group": "Email ingest", "purpose": "IMAP fallback port (993)", "kind": "number", "editable": true, "services": ["jobs"]},
{"name": "IMAP_EMAIL", "group": "Email ingest", "purpose": "IMAP fallback account", "kind": "text", "editable": true, "services": ["jobs"]},
{"name": "IMAP_PASSWORD", "group": "Email ingest", "purpose": "App-specific password, not the account password", "kind": "secret", "editable": true, "services": ["jobs"]},
{"name": "JOB_LEADS_ENABLED", "group": "Job leads", "purpose": "Run the periodic job-lead fetch; \"Check now\" on /cv/leads works either way", "kind": "bool", "editable": true, "services": ["backend"]},
{"name": "JOB_LEADS_INTERVAL", "group": "Job leads", "purpose": "Time between fetches, as a Go duration such as 6h (default 6h)", "kind": "duration", "editable": true, "services": ["backend"]},
{"name": "ADZUNA_APP_ID", "group": "Job leads", "purpose": "Adzuna job search, for adzuna lead sources", "kind": "text", "editable": true, "services": ["backend"], "docsUrl": "https://developer.adzuna.com/admin/access_details"},
{"name": "ADZUNA_APP_KEY", "group": "Job leads", "purpose": "Adzuna job search, for adzuna lead sources", "kind": "secret", "editable": true, "services": ["backend"], "docsUrl": "https://developer.adzuna.com/admin/access_details"},
{"name": "REED_API_KEY", "group": "Job leads", "purpose": "Reed job search, for reed lead sources", "kind": "secret", "editable": true, "services": ["backend"], "docsUrl": "https://www.reed.co.uk/developers/jobseeker"},
{"name": "JOB_LEADS_ENABLED", "group": "Job leads", "purpose": "Run the periodic job-lead fetch; \"Check now\" on /jobs/leads works either way", "kind": "bool", "editable": true, "services": ["jobs"]},
{"name": "JOB_LEADS_INTERVAL", "group": "Job leads", "purpose": "Time between fetches, as a Go duration such as 6h (default 6h)", "kind": "duration", "editable": true, "services": ["jobs"]},
{"name": "ADZUNA_APP_ID", "group": "Job leads", "purpose": "Adzuna job search, for adzuna lead sources", "kind": "text", "editable": true, "services": ["jobs"], "docsUrl": "https://developer.adzuna.com/admin/access_details"},
{"name": "ADZUNA_APP_KEY", "group": "Job leads", "purpose": "Adzuna job search, for adzuna lead sources", "kind": "secret", "editable": true, "services": ["jobs"], "docsUrl": "https://developer.adzuna.com/admin/access_details"},
{"name": "REED_API_KEY", "group": "Job leads", "purpose": "Reed job search, for reed lead sources", "kind": "secret", "editable": true, "services": ["jobs"], "docsUrl": "https://www.reed.co.uk/developers/jobseeker"},
{"name": "ICECAST_SOURCE_PASSWORD", "group": "Radio", "purpose": "Liquidsoap to Icecast, and live broadcasters to the harbor port", "kind": "generated", "editable": true, "services": ["icecast2"], "warning": "Live broadcasting clients must be given the new password."},
{"name": "ICECAST_RELAY_PASSWORD", "group": "Radio", "purpose": "Icecast relay clients", "kind": "generated", "editable": true, "services": ["icecast2"]},
@@ -45,6 +45,7 @@
{"name": "BACKEND_ENDPOINT", "group": "Infrastructure", "purpose": "URL prefix nginx mounts the API at", "kind": "text", "editable": false, "lockedReason": "The Vue app assumes /api."},
{"name": "PYTHON_HOST", "group": "Infrastructure", "purpose": "Python container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "PYTHON_PORT", "group": "Infrastructure", "purpose": "Python listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},
{"name": "JOBS_IMAGE_TAG", "group": "Infrastructure", "purpose": "Job tracker image tag to run (default latest)", "kind": "text", "editable": false, "lockedReason": "Changing it needs a pull: docker compose pull jobs && docker compose up -d jobs."},
{"name": "ICECAST_HOST", "group": "Infrastructure", "purpose": "Icecast container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "ICECAST_PORT", "group": "Infrastructure", "purpose": "Icecast listen port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},
{"name": "ICECAST_MOUNT", "group": "Infrastructure", "purpose": "Listener-facing stream mount", "kind": "text", "editable": false, "lockedReason": "The player and nginx both assume this mount."},
@@ -61,6 +62,9 @@
{"name": "POSTGRES_PASSWORD", "group": "Database", "purpose": "Database password", "kind": "secret", "editable": false, "lockedReason": "Only applied when the volume is first initialised; changing it here locks the backend out."},
{"name": "POSTGRES_DB", "group": "Database", "purpose": "Backend database name", "kind": "text", "editable": false, "lockedReason": "Only applied when the volume is first initialised."},
{"name": "POSTGRES_GITEA_DB", "group": "Database", "purpose": "Gitea database name", "kind": "text", "editable": false, "lockedReason": "Created by hand on a fresh volume."},
{"name": "POSTGRES_JOBS_DB", "group": "Database", "purpose": "Job tracker database name", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; see the job-tracker README."},
{"name": "POSTGRES_JOBS_USER", "group": "Database", "purpose": "Job tracker database role", "kind": "text", "editable": false, "lockedReason": "Created by hand on first install; changing it here locks the tracker out."},
{"name": "POSTGRES_JOBS_PASSWORD", "group": "Database", "purpose": "Job tracker database password", "kind": "secret", "editable": false, "lockedReason": "Set on the role by hand; changing it here locks the tracker out."},
{"name": "GITEA_HOST", "group": "Gitea", "purpose": "Gitea container name and nginx upstream", "kind": "text", "editable": false, "lockedReason": "Renames a container and repoints nginx."},
{"name": "GITEA_PORT", "group": "Gitea", "purpose": "Gitea HTTP port", "kind": "text", "editable": false, "lockedReason": "Renames a container or repoints nginx."},