cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve: some operations in webscript requires a long time to finish

sunquanbin
Champ on-the-rise
Champ on-the-rise
Hi Everyone,

I'm using Java-back webscript handler for Alfresco webscript and I have encountered one problem:

In the Java handler, some operations take quite a long time to finish. Currently the time is only around 10-20s but it may become over minutes in the future. I don't want the user to wait in front of the monitor for minutes (there is perhaps a timeout issue as well).

To be more specific, what the java codes do are:

1. Create about 1000 nodes in Alfresco.
2. Connect to another DB and do some operations (takes minutes).
3. If step 2 failed, delete everything created in step 1.
4. Write the response via the WebScriptResponse writer.

So can I ask is there a suggested solution (or probably a built-in mechanism?) to this case in Alfresco (e.g. run step 2 asynchronously?).

Regards,

Sun 
4 REPLIES 4

romschn
Star Collaborator
Star Collaborator
Business rule running in background could be one solution if you can manage to convert your webscript implementation into an action and set up the business rule as required.

Hope this helps.

mrogers
Star Contributor
Star Contributor
Yes there will typically be a problem if you take over a minute to run.    The first thing to do is to run your command asynchronoulsy,  perhaps via an async action.   The second thing to think about is to use the batch processors if there are large numbers of nodes that need processing.

sunquanbin
Champ on-the-rise
Champ on-the-rise
Thanks for the replies. I have updated my question to be more specific.

I have considered the asynchronous approach. I.E. I can run the time consuming operations in anther thread. Then I will need a mechanism to report back to Alfresco when that thread finished. In addition, I need to create flags on the related nods to monitoring the process. I feel I am re-inventing the wheels if I manually implement this solution.

PS.I have also read the BatchProcessor API at: http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/repo/batch/BatchProcessor.html. But it does not provide information to use it. Can anyone advise me how to get start with that/

Regards,

Sun

kaynezhang
World-Class Innovator
World-Class Innovator
You don't need to create flags on the related nods to monitoring the process.When an asynchronously action has completed execution,alfresco will update action node and set "act:executionActionStatus" property to "Completed" and set "act:executionEndDate" property to the date at which the action is finished.
And for you requirement I think asynchronously  action is more suitable than BatchProcessor.