Package io.kestra.core.tasks.flows
Class WorkingDirectory
java.lang.Object
io.kestra.core.models.tasks.Task
io.kestra.core.tasks.flows.Sequential
io.kestra.core.tasks.flows.WorkingDirectory
- All Implemented Interfaces:
FlowableTask<VoidOutput>,NamespaceFilesInterface
- Direct Known Subclasses:
Worker
@Example(full=true,title="Clone a git repository into the Working Directory and run a Python script",code={"id: gitPython","namespace: dev","","tasks:"," - id: wdir"," type: io.kestra.core.tasks.flows.WorkingDirectory"," tasks:"," - id: cloneRepository"," type: io.kestra.plugin.git.Clone"," url: https://github.com/kestra-io/examples"," branch: main"," - id: python"," type: io.kestra.plugin.scripts.python.Commands"," docker:"," image: ghcr.io/kestra-io/pydata:latest"," commands:"," - python scripts/etl_script.py"}) @Example(full=true,title="Add input and output files within a Working Directory to use them in a Python script",code="id: apiJSONtoMongoDB\nnamespace: dev\n\ntasks:\n- id: wdir\n type: io.kestra.core.tasks.flows.WorkingDirectory\n tasks:\n - id: demoSQL\n type: io.kestra.core.tasks.storages.LocalFiles\n inputs:\n query.sql: |\n SELECT sum(total) as total, avg(quantity) as avg_quantity\n FROM sales;\n\n - id: inlineScript\n type: io.kestra.plugin.scripts.python.Script\n runner: DOCKER\n docker:\n image: python:3.11-slim\n beforeCommands:\n - pip install requests kestra > /dev/null\n warningOnStdErr: false\n script: |\n import requests\n import json\n from kestra import Kestra\n\n with open(\'query.sql\', \'r\') as input_file:\n sql = input_file.read()\n\n response = requests.get(\'https://api.github.com\')\n data = response.json()\n\n with open(\'output.json\', \'w\') as output_file:\n json.dump(data, output_file)\n\n Kestra.outputs({\'receivedSQL\': sql, \'status\': response.status_code})\n\n - id: jsonFiles\n type: io.kestra.core.tasks.storages.LocalFiles\n outputs:\n - output.json\n\n- id: loadToMongoDB\n type: io.kestra.plugin.mongodb.Load\n connection:\n uri: mongodb://host.docker.internal:27017/\n database: local\n collection: github\n from: \"{{outputs.jsonFiles.uris[\'output.json\']}}\"\n") @Example(full=true,code={"id: working-directory","namespace: io.kestra.tests","","tasks:"," - id: working-directory"," type: io.kestra.core.tasks.flows.WorkingDirectory"," tasks:"," - id: first"," type: io.kestra.plugin.scripts.shell.Commands"," commands:"," - \'echo \"{{ taskrun.id }}\" > {{ workingDir }}/stay.txt\'"," - id: second"," type: io.kestra.plugin.scripts.shell.Commands"," commands:"," - |"," echo \'::{\"outputs\": {\"stay\":\"\'$(cat {{ workingDir }}/stay.txt)\'\"}}::\'"}) @Example(full=true,title="A working directory with a cache of the node_modules directory",code="id: node-with-cache\nnamespace: dev\ntasks:\n - id: working-dir\n type: io.kestra.core.tasks.flows.WorkingDirectory\n cache:\n patterns:\n - node_modules/**\n ttl: PT1H\n tasks:\n - id: script\n type: io.kestra.plugin.scripts.node.Script\n beforeCommands:\n - npm install colors\n script: |\n const colors = require(\"colors\");\n console.log(colors.red(\"Hello\"));")
public class WorkingDirectory
extends Sequential
implements NamespaceFilesInterface
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class io.kestra.core.tasks.flows.Sequential
errors -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidpostExecuteTasks(RunContext runContext, TaskRun taskRun) voidpreExecuteTasks(RunContext runContext, TaskRun taskRun) resolveNexts(RunContext runContext, Execution execution, TaskRun parentTaskRun) Resolve next tasks to run for an execution.workerTask(TaskRun parent, Task task, RunContext runContext) Methods inherited from class io.kestra.core.tasks.flows.Sequential
allChildTasks, childTasks, tasksTreeMethods inherited from class io.kestra.core.models.tasks.Task
findById, findById, isFlowable, isSendToWorkerTaskMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.kestra.core.models.tasks.FlowableTask
getErrors, outputs, resolveStateMethods inherited from interface io.kestra.core.models.tasks.NamespaceFilesInterface
getNamespaceFiles
-
Constructor Details
-
WorkingDirectory
public WorkingDirectory()
-
-
Method Details
-
resolveNexts
public List<NextTaskRun> resolveNexts(RunContext runContext, Execution execution, TaskRun parentTaskRun) throws IllegalVariableEvaluationException Description copied from interface:FlowableTaskResolve next tasks to run for an execution.For a normal flowable, it should be the subsequent task, for a parallel flowable (such as Parallel, ForEachItem, ...), it should be a list of the next subsequent tasks of the size of the concurrency of the task.
- Specified by:
resolveNextsin interfaceFlowableTask<VoidOutput>- Overrides:
resolveNextsin classSequential- Throws:
IllegalVariableEvaluationException
-
workerTask
-
preExecuteTasks
- Throws:
Exception
-
postExecuteTasks
-