[1.2.4] Design Advice

52 views
Skip to first unread message

Mikael

unread,
Apr 30, 2012, 8:55:12 AM4/30/12
to play-fr...@googlegroups.com
I have the following requirements for some Job control:
  • Log the start time of the Job in the DB
  • Log the finish time of the Job in the DB 
  • Log the status the Job in the DB 
  • Control Job execution so the same job cannot run twice at the same time.
My initial thought is to have a JobControl object extend Model containing the times and status.
I can create one instance of the JobControl per job and add these to the Cache (EhCache).
Every access to retrieve/add these to the cache will  probably need to be synchronised.
At the start of a job I can then create a new Control object with the time if not present in the cache or abort the job if there is such an object.

When the Job completes then update the end time and status, persist the object and remove it from the cache.

Can anyone see any issues with that (keeping in mind there is only one instance of Play running) or got any better ideas?

Tx.

Allen

unread,
May 1, 2012, 3:40:36 AM5/1/12
to play-fr...@googlegroups.com
seems to be a good approach. Only take care that the running time of a job does not extend the time the cache holds
the job object. If this happens, another job would be started (its like a lock marker for your job).

In general you dont need to put the job in the cache. You could every time ask the database directly for an open (still running) job object.
This is maybe less error prone as you should not rely on a cache to much.

best,
allen

Mikael

unread,
May 1, 2012, 6:14:55 AM5/1/12
to play-fr...@googlegroups.com
Hey Allen,

That's a good point. My Asynchronous Jobs are kicked off from the controllers if the computation has not been performed previously. 
I could check in the controller if the job has been started from a previous request.

How would you handle:

  • User A makes request for a report.
  • Async Job is started and the request thread freed whilst the report is computing
  • Meanwhile User B makes the same request whilst the report is computing.
  • The job will not be kicked off as there is already a start time.

What should the controller return to user B?
Perhaps a message indicating that the report is being processed and to try again in a few minutes?

Allen

unread,
May 1, 2012, 11:36:11 AM5/1/12
to play-fr...@googlegroups.com
I would put a Job Model Object for every report into the database.
Each Job Model has a state (processing and finished).

If you make your calculation, maybe you can put also the result into the Job Object, so you have anything in one place.

When a job is running, and you have the data, you could save also the percentage how much is already done.
You can then display to the user B (maybe you refresh the page with a meta-refresh) so the user can see the progress.

As the User A did start the job asynchronously, it should not block the requests of User B.
Finally I would think about an max. allowed running time for an task and stop the job if it runs to long.

Best,
Allen
Reply all
Reply to author
Forward
0 new messages