Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling play.jobs.Job from running while in test mode in play framework

Using play framework 1.2.4 with scala. I have few play jobs that looks like like

@OnApplicationStart class MyOtherJob extends Job {  ...  } 

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

These jobs are running while the application is in test mode, so they mess up things. How can I disable them from running while testing?

I tried the following application config, didn't help:

# Jobs executor 
# ~~~~~~ 
# Size of the Jobs pool 
play.jobs.pool=10 
test.play.jobs.pool=0 
test.cron.queue.every=never 
dev.cron.queue.every=20s 
prod.cron.queue.every=20s 
test.cron.onApplicationStart.trigger=never 
dev.cron.onApplicationStart.trigger=auto 
prod.cron.onApplicationStart.trigger=auto 
like image 951
Eishay Smith Avatar asked Oct 09 '22 04:10

Eishay Smith


1 Answers

It is possible to check if Play is running in test mode using the following syntax.

play.Play.runingInTestMode()

Note: the spelling mistake is not accidental. That is the method name in the API.

Therefore, in your Jobs, you should be able to wrap the job execution around an IF statement using the above, and therefore, preventing test mode jobs.

like image 120
Codemwnci Avatar answered Oct 13 '22 12:10

Codemwnci