How to run job in only one pod using @Scheduled in Spring Boot

1.1k Views Asked by At

I'm using @Scheduled annotation to schedule a job in Spring Boot. My code is running in Kubernetes cluster. Job is working fine, but when I start multiple pods, each pod starts running the job at the given time. I want only one to run the job. Read about Shedlock but it doesn't seem to work with Firestore database. Is there a way to achieve this behaviour with Firestore database?

1

There are 1 best solutions below

0
Mark On

First, why would you want to scale your scheduled job? scheduled job should not be scaled. It's better if you separate it with the micro-service arc in mind.

if your concern is price, so that you want to combine your scheduled job with other services, I dont think that Firestore could help you in this case. Rather, you could change your scheduler into a Http server, and use Google Cloud Scheduler to invoke your pod.