Hello everyone,
I have a question: How can a timer function be integrated into Alfresco without causing excessive CPU consumption? Presently, we have an Alfresco rule triggering the execution of a JS script. Within this script, a timer function of the following type is being used:
function wait(sleepDuration) { var startTimestamp = new Date().getTime(); while (new Date().getTime() < startTimestamp + sleepDuration) { /* Do nothing */ } }
To clarify, this `wait` function is called before executing the `retrieveModifiedNodes(node)` function. This delay allows SolR time to index. Without it, the retrieval isn't always complete.
However, we've observed that this method logically demands a lot of CPU resources.
We're aware that Alfresco uses the Rhino engine for JavaScript. Therefore, we're seeking the best approach to adopt. For instance, would it be more suitable within the context of Alfresco to use this method instead:
setTimeout(function() { var modifiedNodes = retrieveModifiedNodes(node); }, 60000);
Or are there other more appropriate methods available?
The ACS internal JavaScript API is not meant to be used for asynchronous use cases / internal timers, and has no special support for it. setTimeout is a browser JS function that is not available. A script loaded / executed from the classpath (instead of being stored in the Data Dictionary) can access the Java interoperability feature to use the Java Thread.sleep() method to wait without spending CPU cycles.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.