How to create a job and queue in a grails applicat

2019-09-04 11:45发布

I have a grails application in which the user uploads a document and my application does various things with the uploaded file. Some of these tasks take a long time so the user has to wait to see the next page.

I want to change this behavior such that the user uploads the file and then immediately sees the next page. In the background the uploaded file will be queued. Later I want to pick-up files from the queue and process them in the order they were received.

What are some options available to a grails application to accomplish this? It'll be best if I can be pointed to a tutorial

2条回答
乱世女痞
2楼-- · 2019-09-04 12:31

I think you are looking for something like executorService

Refer

You can use runasynch { } closure to achieve your requirement

查看更多
我命由我不由天
3楼-- · 2019-09-04 12:49

Based on the original question about Job and Queue, there are various ways you can have a message listener in your grails application. Some of them are:

When job execution is concerned, the unanimous plugins would be either:

Now coming to the objective of your question, you can also achieve the document upload functionality asynchronously if grails version is below 2.3 or you can leverage the Async support provided in Grails version 2.3 which sticks to "fire-and-forget" policy. User fires the document upload request and forgets about it, and gets notified when the task gets completed.

If you are cognizant of "Promises" in common JS based frameworks (for eg: AngularJS) then using Promises in grails 2.3 will be an easier approach for you.

查看更多
登录 后发表回答