Files
spring-async-demo/scheduling/docker-compose.yml
Ankur Mhatre eaa8171966 Add the scheduling module
Three replicas of one application against one PostgreSQL database, proving
duplicate @Scheduled execution and then removing it with ShedLock: 24
executions where 8 were due, then 7 for 7 ticks.

Also measured: @SchedulerLock without @EnableSchedulerLock does nothing and
warns about nothing; spring.task.scheduling.pool.size=1 does not starve a
fixedRate job but delays it and fires 35 of 40 executions in a burst; and a
node whose clock is 40 seconds fast takes a live lock unless the provider
uses usingDbTime().
2026-09-01 23:32:16 +05:30

52 lines
1.6 KiB
YAML

# 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}