Skip to content

Commit acf3469

Browse files
committed
feat(workflow): add LambdaTask builder for TaskType.LAMBDA
Closes #427 TaskType.LAMBDA existed in the enum but had no builder class, so LAMBDA tasks could only be constructed from raw dicts via the Python SDK. Add a LambdaTask builder that mirrors InlineTask: it sets scriptExpression from the script argument and merges any bindings into input_parameters. Signed-off-by: rahul188 <rahulkuchhadia@gmail.com>
1 parent 7481aed commit acf3469

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import annotations
2+
from typing import Dict, Optional
3+
from typing_extensions import Self
4+
5+
from conductor.client.workflow.task.task import TaskInterface
6+
from conductor.client.workflow.task.task_type import TaskType
7+
8+
9+
class LambdaTask(TaskInterface):
10+
def __init__(self, task_ref_name: str, script: str, bindings: Optional[Dict[str, str]] = None) -> Self:
11+
super().__init__(
12+
task_reference_name=task_ref_name,
13+
task_type=TaskType.LAMBDA,
14+
input_parameters={
15+
"scriptExpression": script,
16+
}
17+
)
18+
if bindings is not None:
19+
self.input_parameters.update(bindings)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from conductor.client.workflow.task.lambda_task import LambdaTask
2+
from conductor.client.workflow.task.task_type import TaskType
3+
4+
SCRIPT = "(function(){ return {out: $.x + 1}; })()"
5+
6+
7+
def test_lambda_task_builds_script_expression():
8+
task = LambdaTask(task_ref_name="lambda_ref", script=SCRIPT)
9+
assert task.task_reference_name == "lambda_ref"
10+
assert task.input_parameters == {"scriptExpression": SCRIPT}
11+
12+
workflow_task = task.to_workflow_task()
13+
assert workflow_task.type == TaskType.LAMBDA.value
14+
assert workflow_task.input_parameters["scriptExpression"] == SCRIPT
15+
16+
17+
def test_lambda_task_merges_bindings():
18+
task = LambdaTask(
19+
task_ref_name="lambda_ref",
20+
script=SCRIPT,
21+
bindings={"x": "${workflow.input.x}"},
22+
)
23+
assert task.input_parameters == {
24+
"scriptExpression": SCRIPT,
25+
"x": "${workflow.input.x}",
26+
}

0 commit comments

Comments
 (0)