Executable code in service task / any other task #248
-
Hello @ralphhanna, Is there any way that we can write the code in camunda to execute. I know that we have task / execution listeners, but
For solving my question 1, i know that we can write functionalities in appservices, but for that it would need to make a code change in the PROD to support this. I'm looking for a solution to write some small code blocks to execute. Please share your thoughts ? also @ALL, please share me any solutions if you already had ins solving the above mentioned problems. Thank You in advance 🚀 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
bit confused about your mention of camunda? you mean in the XML file.
It is easy to customize your own scriptHandler and modify the configuration.ts class to include it scriptHandler: function(server) {
return new ScriptHandler();
}, In Summary, the answer is Yes, you can allow JavaScript code to access installed libraries and Yes you can allow Scripts to be Python code |
Beta Was this translation helpful? Give feedback.
-
To customize ScriptHandler, scriptHandler: function(server) {
return new CustomScriptHandler();
}, As for Python; have a look at this link |
Beta Was this translation helpful? Give feedback.
-
Ok, I was able to invoke python as a web service from a workflow: 1. add webService method to AppServices async webService(input,context) {
const axios = require('axios');
let url='http://localhost:5000/run';
let data={ a: 2, b: 3 };
let res=await axios.post(url, data)
console.log('Result from Python:', res.data);
} 2 have a python running as a web serverfrom flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/hi', methods=['GET'])
def say_hi():
return "Hi there! 👋", 200
@app.route('/run', methods=['POST'])
def run():
data = request.json
result = data['a'] + data['b']
return jsonify({'result': result})
if __name__ == '__main__':
app.run(port=5000) 3. Invoke from workflow (any node start/end trigger)appServices.webService({},this); |
Beta Was this translation helpful? Give feedback.
-
However, If you are looking at just python snippet throughout the workflow here is another option we can entertain: $py print("Hi Python") By Inserting `$py ' at the start of any script, we execute as a python code by spawning a separate process |
Beta Was this translation helpful? Give feedback.
-
This is now available in latest release 2.3.2 |
Beta Was this translation helpful? Give feedback.
However, If you are looking at just python snippet throughout the workflow here is another option we can entertain:
By Inserting `$py ' at the start of any script, we execute as a python code by spawning a separate process