The CLI supports defining Conductor workflows using JavaScript instead of JSON. This allows you to write workflows in a more programmatic way with helper functions and inline task definitions.
Your JavaScript file must define a workflow() function that returns an object containing:
name: Workflow namedescription: Workflow descriptionversion: Workflow version numbertasks: Array of task definitionsinputParameters: (optional) Array of input parameter namesoutputParameters: (optional) Output parameter mappings
conductor workflow create workflow.js --jsThe --js flag tells the CLI to process the file as JavaScript.
function workflow() {
return {
name: "my_js_workflow",
description: "Sample JS Workflow",
version: 1,
tasks: [
{
name: "process_data",
taskReferenceName: "process_data_ref",
type: "SIMPLE",
inputParameters: {
data: "${workflow.input.data}"
}
},
{
name: "inline_fn",
type: "INLINE",
inputParameters: {},
function: function transform() {
return {
result: "transformed"
};
}
},
{
// WAIT task - taskReferenceName auto-generated from name
type: "WAIT",
duration: "30s"
},
{
name: "final_task",
type: "SIMPLE",
inputParameters: {
input: "${inline_fn.output.result}"
}
}
],
inputParameters: ["data"],
outputParameters: {
result: "${final_task.output}"
}
};
}You can define inline JavaScript functions that will be automatically converted to INLINE tasks with GraalJS evaluator:
{
name: "inline_fn",
type: "INLINE",
inputParameters: {},
function: function myFunction() {
// Your JavaScript code here
return {
result: "some value"
};
}
}The transformation will:
- Convert the task
typeto"INLINE" - Stringify the function and set it as the
expressionparameter - Set
evaluatorTypeto"graaljs"
For WAIT tasks, you can simply specify the duration:
{
type: "WAIT",
duration: "30s"
}The transformation will:
- Auto-generate the task
nameas"WAIT"if not provided - Move
durationtoinputParameters.duration
If you don't provide a taskReferenceName, it will be automatically generated from the task name.
When you run conductor workflow create workflow.js --js, the CLI:
- Loads your JavaScript file
- Executes the
workflow()function in a JavaScript VM (goja) - Applies transformations to the returned object:
- Converts inline functions to INLINE tasks
- Processes WAIT tasks
- Auto-generates missing taskReferenceNames
- Converts the result to JSON
- Registers the workflow with Conductor
- The JavaScript runtime is sandboxed (goja)
- No access to Node.js modules or external dependencies
- Only the
workflow()function is executed - Error handling is basic - syntax errors may not be clearly reported
To update an existing JavaScript workflow:
conductor workflow update workflow.js --js- Always initialize
inputParameters: {}for tasks with inline functions - Test your JavaScript syntax before uploading
- Use descriptive task names for better readability
- Remember that this is experimental - fallback to JSON if you encounter issues