Package io.kestra.plugin.graalvm.python
Class Eval
java.lang.Object
io.kestra.core.models.tasks.Task
io.kestra.plugin.graalvm.AbstractEval
io.kestra.plugin.graalvm.python.Eval
- All Implemented Interfaces:
io.kestra.core.models.Plugin,io.kestra.core.models.PluginVersioning,io.kestra.core.models.tasks.RunnableTask<AbstractEval.Output>,io.kestra.core.models.tasks.TaskInterface,io.kestra.core.models.WorkerJobLifecycle
@Plugin(examples={@Example(full=true,title="Parse a downloaded JSON and update one of its fields.",code="id: parse_json_data\nnamespace: company.team\n\ntasks:\n - id: download\n type: io.kestra.plugin.core.http.Download\n uri: http://xkcd.com/info.0.json\n\n - id: graal\n type: io.kestra.plugin.graalvm.python.Eval\n outputs:\n - data\n script: |\n data = {{ read(outputs.download.uri )}}\n data[\"next_month\"] = int(data[\"month\"]) + 1\n"),@Example(full=true,title="Execute a Python script using the GraalVM scripting engine.",code="id: evalPython\nnamespace: company.team\n\ntasks:\n - id: evalPython\n type: io.kestra.plugin.graalvm.python.Eval\n outputs:\n - out\n - map\n script: |\n import java\n import java.io.File as File\n import java.io.FileOutputStream as FileOutputStream\n # types other than one coming from the Java SDK must be defined this way\n Counter = java.type(\"io.kestra.core.models.executions.metrics.Counter\")\n logger.info(\'Task started\')\n runContext.metric(Counter.of(\'total\', 666, \'name\', \'bla\'))\n map = {\'test\': \'here\'}\n tempFile = runContext.workingDir().createTempFile().toFile()\n output = FileOutputStream(tempFile)\n output.write(\'Hello World\'.encode(\'utf-8\'))\n out = runContext.storage().putFile(tempFile)\n {\"map\": map, \"out\": out}"),@Example(full=true,title="Define a Python module, then execute a script that imports this module using the GraalVM scripting engine.",code="id: evalPython\nnamespace: company.team\n\ntasks:\n - id: evalPython\n type: io.kestra.plugin.graalvm.python.Eval\n modules:\n hello.py: |\n def hello(name):\n return(\"Hello \" + name)\n script: |\n import hello\n logger.info(hello.hello(\"Kestra\"))")},metrics=@Metric(name="records",type="counter",unit="count",description="Tracks a user defined numeric value emitted from the Python script, such as the number of processed records or computed results."))
public class Eval
extends AbstractEval
-
Nested Class Summary
Nested classes/interfaces inherited from class io.kestra.plugin.graalvm.AbstractEval
AbstractEval.OutputNested classes/interfaces inherited from class io.kestra.core.models.tasks.Task
io.kestra.core.models.tasks.Task.TaskBuilder<C extends io.kestra.core.models.tasks.Task,B extends io.kestra.core.models.tasks.Task.TaskBuilder<C, B>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @NotNull io.kestra.core.models.property.Property<String> Fields inherited from class io.kestra.plugin.graalvm.AbstractEval
outputsFields inherited from class io.kestra.core.models.tasks.Task
disabled, id, retry, timeout, type, versionFields inherited from interface io.kestra.core.models.PluginVersioning
DESCRIPTION, TITLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.graalvm.polyglot.ContextbuildContext(io.kestra.core.runners.RunContext runContext, OutputStream out, OutputStream err) protected org.graalvm.polyglot.Context.BuildercontextBuilder(io.kestra.core.runners.RunContext runContext) protected org.graalvm.polyglot.SourcegenerateSource(String languageId, io.kestra.core.runners.RunContext runContext) protected org.graalvm.polyglot.ValuegetBindings(org.graalvm.polyglot.Context context, String languageId) io.kestra.core.models.property.Property<String> run(io.kestra.core.runners.RunContext runContext) Methods inherited from class io.kestra.plugin.graalvm.AbstractEval
runMethods inherited from class io.kestra.core.models.tasks.Task
findById, findById, getAssets, getDescription, getDisabled, getId, getLogLevel, getRetry, getRunIf, getTaskCache, getTimeout, getType, getVersion, getWorkerGroup, isAllowFailure, isAllowWarning, isFlowable, isLogToFile, 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.WorkerJobLifecycle
kill, stop
-
Field Details
-
script
@NotNull @PluginProperty(group="main") protected @NotNull io.kestra.core.models.property.Property<String> script
-
-
Constructor Details
-
Eval
public Eval()
-
-
Method Details
-
getScript
-
run
- Throws:
Exception
-
contextBuilder
protected org.graalvm.polyglot.Context.Builder contextBuilder(io.kestra.core.runners.RunContext runContext) -
buildContext
protected org.graalvm.polyglot.Context buildContext(io.kestra.core.runners.RunContext runContext, OutputStream out, OutputStream err) -
getBindings
protected org.graalvm.polyglot.Value getBindings(org.graalvm.polyglot.Context context, String languageId) -
generateSource
protected org.graalvm.polyglot.Source generateSource(String languageId, io.kestra.core.runners.RunContext runContext) throws io.kestra.core.exceptions.IllegalVariableEvaluationException - Throws:
io.kestra.core.exceptions.IllegalVariableEvaluationException
-