I'm coming from the rails world and have been read...
# spring
t
I'm coming from the rails world and have been reading up on spring, is there a background job runner library I can use along the lines of ActiveJob & (sidekiq | goodjob) in spring? I have looked at spring batch but I'm not seeing a background job executor process. I did find jobrunr though, so I'm curious what others are using to run background jobs?
t
Is Spring Scheduler what you are looking for?
t
are you referring to https://spring.io/guides/gs/scheduling-tasks/ ? If so I don't think so because I'm not looking to schedule a job every x seconds, I'm looking to create a job at any point that does a long computation, and I would like to have it execute immediately in the background job executor
t
Never really had to do it myself, but a quick google got me this: https://rafiqnayan.blogspot.com/2016/10/run-tasks-in-background-in-spring.html
t
that's running a task in the background in the same process, I'm looking to decouple the job from the initiation process, so it would look something like: 1. POST /start 2. enqueue a job into the database 3. separate background job executor process that lives on another machine sees that a job got enqueued, and picks it up
t
So.. if i get it correctly you are actually looking for a way to continuously look at a table and execute a job based on a record in that table?
t
ya, I believe this is what jobrunr (java) is doing
t
Well, spring scheduler should be ok with doing that? as in, make a spring app and check the table every X seconds and start the job?
r
Hey, accessing DB constantly for just checking for new entry sounds inefficient. It's the reason Observer design pattern came to be. In this case, I would suggest just doing another call to the other machine from initial machine. so After 1, 2) Call other other machine to queue job. Also, register for when job done ? Or result. 3) Other machine so do as you wish with the job and setup. But you know about the job rather than asking if there is a job. Unless this a scheduled job, I don't think you would need to utilize the DB for that.
p
Jobrunr has been great for us for a few different service use cases (including reliable background job running like you want), I recommend it. It's easy to integrate using the spring starter.