Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concurrently running Schedules Jobs using Play! Framework

I have a Play! Framework Job that executes every 30 seconds:

@Every("30s")
public class MyJob extends Job { ... }

This job does a few things such as reading e-mails and writing to the DB. However, it is possible that the job may not finish within 30 seconds. If the job takes longer than 30 seconds, I would like to kill the subsequent job that tries to start while the original job is still in progress. Is there a way to do this? or even pause the subsequent job until the original completes its work?

like image 328
digiarnie Avatar asked Dec 22 '22 12:12

digiarnie


1 Answers

as far as I know you don't have to kill the job. I created a job than had to run every minute, but in some scenarios it could (potentially) run for longer than a minute.

I did some testing, and be aware that I may have done them in the wrong way, but Play doesn't launch a new instance of the Job if it is already running. Once the job finishes, it will run the next instance in the expected time. Take it as if Play treats Jobs as "Singletons", only 1 of a given type active at a given time.

So, no, you don't need to kill or check anything. Awesome, isn't it? ;)

like image 107
Pere Villega Avatar answered Dec 29 '22 00:12

Pere Villega