application1: @Service public class Application1Service { private static final Logger log = LoggerFactory.getLogger(Application1Service.class); @Recurring(id = "application1RecurringJob", cron = "*/5 * * * * *") @Job(name = "Recurring job from application1") public void process(){ log.info("Executing application1 recurring job every 5 sec {}",System.currentTimeMillis()); } } application1.properties spring: datasource: url: jdbc:postgresql://localhost:5432/jobrunr_db username: postgres password: admin driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: update server: port: 8081
application2: @Service public class Application2Service { private static final Logger log = LoggerFactory.getLogger(Application2Service.class); @Recurring(id = "application2RecurringJob", cron = "*/10 * * * * *") @Job(name = "Recurring job from application2") public void process(){ log.info("Executing application2 recurring job every 10 sec {}",System.currentTimeMillis()); } }
application2.properties spring: datasource: url: jdbc:postgresql://localhost:5432/jobrunr_db username: postgres password: admin driver-class-name: org.postgresql.Driver jpa: hibernate: ddl-auto: update server: port: 8080
org:
jobrunr:
dashboard:
enabled: true
database:
skip-create: false
background-job-server:
enabled: true
name: app2-server
OUT PUT :
Application1 error :
org.jobrunr.scheduling.exceptions.JobClassNotFoundException: com.hbzservices.api.application2.service.Application2Service.process2()
Application2 errors : org.jobrunr.scheduling.exceptions.JobClassNotFoundException: com.hbzservices.api.application1.service.Application1Service.process()
Expectations: Application1 will run only its own jobs and not pick up jobs from Application2 and vice versa.
The setup you have will not work as JobRunr expects each application to have one single database.
In your case, there are 3 options:
In the example above, JobRunr thinks that you're scaling horizontally (e.g. adding more processing power to process jobs faster) as both applications are using the same database. If you split your applications to have multiple databases, everything will work as expected.