# Three replicas and one database, which is the smallest deployment in which a @Scheduled method # misbehaves. Run `docker compose up --scale app=3` if you would rather set the replica count # from the command line; the three named services below exist so that each one gets a stable # INSTANCE_ID in the transcript. # # docker compose up --build # docker compose exec db psql -U app -d shedlockdemo -c \ # "select instance_id, count(*) from job_execution group by instance_id" # # SPRING_PROFILES_ACTIVE=unlocked reproduces the duplicate executions; switch it to `locked` to # watch the count collapse to one per tick. services: db: image: postgres:17 environment: POSTGRES_USER: app POSTGRES_DB: shedlockdemo POSTGRES_HOST_AUTH_METHOD: trust ports: ["5432:5432"] healthcheck: test: ["CMD-SHELL", "pg_isready -U app -d shedlockdemo"] interval: 2s timeout: 3s retries: 20 replica-1: &replica build: . depends_on: db: { condition: service_healthy } environment: DB_URL: jdbc:postgresql://db:5432/shedlockdemo DB_USER: app INSTANCE_ID: replica-1 SPRING_PROFILES_ACTIVE: ${PROFILE:-unlocked} replica-2: <<: *replica environment: DB_URL: jdbc:postgresql://db:5432/shedlockdemo DB_USER: app INSTANCE_ID: replica-2 SPRING_PROFILES_ACTIVE: ${PROFILE:-unlocked} replica-3: <<: *replica environment: DB_URL: jdbc:postgresql://db:5432/shedlockdemo DB_USER: app INSTANCE_ID: replica-3 SPRING_PROFILES_ACTIVE: ${PROFILE:-unlocked}