Stop Javascript Console execution

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

Stop Javascript Console execution

Hello,

Q1: Is there a way to say STOP/EXIT in the javascript code inserted into the JS Console?

(i.e., is there a way to stop the JS Console running in the Alfresco repository?)

Detailed context

I need to update cm:storeName for 1,5 million Alfresco nodes.

I want to split the processing by date intervals (e.g., process all nodes created in January 2018).

I know the js code is encapsulated in a transaction and search queries return at most 1000 results.

I want the js code to run continuously ("Run Like Crazy" option), so I can process more than 1000 objects after I start running the js code.

var def = { query: "=cm:storeName:\"storeX\" AND @cm:created:[\"2018-01-01\" TO \"2018-01-31\"]", store: "workspace://SpacesStore", language: "fts-alfresco", };
var nodes = search.query(def);
for each(var node in nodes) {
    node.properties["cm:storeName"] = "storeY";
    node.save();
}‍‍‍‍‍

nodes.length is at most 1000; when everything is done (all content is transferred to storeY), nodes.length is 0.

The problem is: even when all content is moved to storeY, the js code continues to run and I believe I need to restart the tomcat, which is very inconvenient. I want to say something like: "if nodes.length gets 0, please stop/exit".

Q2: If I cannot say stop/exit, is there another easy way of changing cm:storeName for all the objects (without tomcat restart)?

Thank you.

Liviu

2 Replies
Highlighted
Member II

Re: Stop Javascript Console execution

There was a misunderstanding on my side.

Clarifications

There is a js-console client (in Share) and a js-console server (in the Repository).
Run Like Crazy = the client continuously sends the js snippet to the js-console server.

Misuderstanding: I thought Run Like Crazy = the server runs continously the js snippet.

As a result:

  1. Closing the client (closing the tab in the browser) would stop the js snippet being sent to the js-console server. The same result can be achieved by setting Run Like Crazy to off.
  2. There is no way to stop the execution of a js snippet once the js-console server has received it (except by killing tomcat on the server side, of course)
Highlighted
Customer

Re: Stop Javascript Console execution

Definitely, for doing a massive task as you commented, JS Console may be not the best option. You can not stop the process once started.

In your case, I will use either CMIS script or to use a custom webscript.

In my experience, the second option is very much faster. With a CMIS script, I get more control over the process and it is easily batch-able and cron-able, while with a custom webscript execution I limit to a batch size of updates because of caches, and I use logger.warn in my js code to see in the logs how is going the custom process. In both cases, I got a complete list of target uuids in some file, and then I split the executions for doing 5000-10000 batches.

Regards.

--C.