Playframework concurrent jobs management

天涯浪子 提交于 2019-12-12 18:28:00

问题


I would like to have some advise on multiple concurrent job management in play : in fact, i'm using in my application two distincts jobs :

  • the first job is a quick one : it tries to reach two distinct url using WS.url() method and record the resulting status into database. Three retry are done if a website does not responding. This task takes less than 20s to finish, and is going to be run every 5 minutes.

  • the second job is a slow one : it parses content into both websites if their status recorded into database is ok. This process takes around 2 minutes, and is going to be done every hour.

I wanted to be sure that if one job is running, another one can't be raised, and is going to wait the end of current to start. I'm very new with locks usage and concurrent access, so every advise is precious to me !


回答1:


The solution would be to keep some flag in the database (where you record the status) so the second job detects if it can run or not. Now, that would be a solution but it could have some issues in certain scenarios.

Given that both jobs are linked (one "pings" a url, the other parses it), that the first is very fast en execution, that (in your given scenario) the status retrieved by the first job is irrelevant to anyone except the second job and that pinging a url 12 times per hour when you will use the latest result once per hour seems a waste of resources (both on your site and the sites you ping), I would suggest to merge both tasks into a single job.

If you have one job, you won't have to worry anymore about concurrency. Just run it once per hour.




回答2:


If you want to make it simple you could start the second job in the first one..

Your last line after checking the service is up

new URLParserJob().now();


来源:https://stackoverflow.com/questions/8402552/playframework-concurrent-jobs-management

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!