Add support for Run.script (Javascript)#962
Add support for Run.script (Javascript)#962fjtirado merged 8 commits intoserverlessworkflow:mainfrom
Conversation
There was a problem hiding this comment.
I know this is a draft but I think is good I wrote a long general comment, since this PR requires some deep refactor.
The goal should be to not add Javascript or Python dependencies to the core.
With that spirit, you need a RunScriptTask in the core modules that selects either the JavaScript or the Python implementation (use the language id to select the right implementation, all implementation being loaded through service loading to not create dependencies)
Then you have another module with the java script specific code plus the javascript library (the java script implementation class being loaded thorugh service loader)
About this specific module, we need to split better between init (parsing) and apply (runtime). rather than having an Executor that does all the parsing at runtime at the end, you will need several "functor" classes that give you the source, the environmment and so on.
Finally, JavaScript should be executed on embedded mode, not running an external process.
I will try to comment on specific cases.
| String value = | ||
| ExpressionUtils.isExpr(entry.getValue()) | ||
| ? WorkflowUtils.buildStringResolver( | ||
| application, | ||
| entry.getValue().toString(), | ||
| taskContext.input().asJavaObject()) | ||
| .apply(workflowContext, taskContext, taskContext.input()) | ||
| : entry.getValue().toString(); |
There was a problem hiding this comment.
This is an example of functor I mention in the general comment.
The idea is that you generate a Map<String,WorkflowValueResolver during init, by using Workfloutils.buildStringFilter (WorkflowApplication appl, String expression), and at runtime you actually invoke the apply (passing the Workflowcontext, TaskContext and WorkflowModel passed to apply method)
impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunScriptExecutor.java
Outdated
Show resolved
Hide resolved
fjtirado
left a comment
There was a problem hiding this comment.
Added a couple of comments trying to illustrate my previous comment.
impl/core/src/main/java/io/serverlessworkflow/impl/executors/RunScriptExecutor.java
Outdated
Show resolved
Hide resolved
Great comment, I was inclined to create a separate module, especially since the dependency is quite large and really specific. Thanks, I will change it in the next commits. |
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Signed-off-by: fjtirado <ftirados@redhat.com>
Signed-off-by: fjtirado <ftirados@redhat.com>
Signed-off-by: fjtirado <ftirados@redhat.com>
Many thanks for submitting your Pull Request ❤️!
What this PR does / why we need it:
Special notes for reviewers:
Additional information (if needed):