Query On External Resource(Script Task)

Hi,
Will externalizing inline script to js/groovy file(deployment://hello.js) have any impact on performance?
As per my knowledge, default behavior of engine is, it will cache the script code so that no need to compile every time. Will the same behavior hold when we externalize the script?

Kindly provide inputs.

Hello my friend!

Camunda’s default behavior will always be to attempt caching to optimize performance.
It can even be considered a good practice to externalize scripts in large projects, as this can facilitate maintenance.

The first time that the Camunda Engine needs to call your script, it will check whether it has already been triggered previously, if not, a “script engine” is created, and if the engine declares that it is thread-safe, the script is stored in cache, so that in future calls it is not necessary to create a new instance of the script engine.

You can understand a little better about this in Camunda’s official documentation on scripts.

I hope this helps!

William Robert Alves

2 Likes

Thank you @WilliamR.Alves
I have follow up question on this. Is it good practice to keep bulky code in these external js files. Say 100-150 lines of code.
Or is it better to move this to external system and call them via API(service task).

I’m trying to find the best approach out of these when you have complex logic

I’m happy to be able to help my friend! :smile:

Choosing between script or API will depend on the context of your code.

For example, if this code of yours is related to a specific process within Camunda, keeping the code as part of this process would be the best choice for me (i.e., scripting is better).

But if this code is not related to a specific process, and you believe that you will need to reuse the code, calling in other parts within your process and even in external applications (other APIs), then it makes sense to place this code as a API.

Just remember that by creating this as an API, we lose the power of caching that we talked about earlier.

William Robert Alves

2 Likes

Basically I’m referring to data transformation code which will be passed to next http connector task

1 Like

In this case, if we do not need to call this API from another application, and possibly there will be no “reuse” of the code outside of Camunda, I believe that the best option is to continue with the scripts.

William Robert Alves

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.