Search in sources :

Example 1 with Template

use of io.kestra.core.tasks.flows.Template in project kestra by kestra-io.

the class FlowJoinerTransformer method transform.

@Override
public Executor transform(String key, Executor executor) {
    Flow flow;
    try {
        // pooling of new flow can be delayed on ExecutorStore, we maybe need to wait that the flow is updated
        flow = Await.until(() -> flowExecutorInterface.findByExecution(executor.getExecution()).orElse(null), Duration.ofMillis(100), Duration.ofMinutes(5));
    } catch (TimeoutException e) {
        return executor.withException(new Exception("Unable to find flow with namespace: '" + executor.getExecution().getNamespace() + "'" + ", id: '" + executor.getExecution().getFlowId() + "', " + "revision '" + executor.getExecution().getFlowRevision() + "'"), "joinFlow");
    }
    if (!withDefaults) {
        return executor.withFlow(flow);
    }
    try {
        flow = Template.injectTemplate(flow, executor.getExecution(), (namespace, id) -> this.templateExecutorInterface.findById(namespace, id).orElse(null));
    } catch (InternalException e) {
        log.warn("Failed to inject template", e);
    }
    Flow flowWithDefaults = taskDefaultService.injectDefaults(flow, executor.getExecution());
    return executor.withFlow(flowWithDefaults);
}
Also used : ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) FlowExecutorInterface(io.kestra.core.runners.FlowExecutorInterface) Slf4j(lombok.extern.slf4j.Slf4j) Await(io.kestra.core.utils.Await) TaskDefaultService(io.kestra.core.services.TaskDefaultService) Duration(java.time.Duration) Executor(io.kestra.core.runners.Executor) ValueTransformerWithKey(org.apache.kafka.streams.kstream.ValueTransformerWithKey) TimeoutException(java.util.concurrent.TimeoutException) Flow(io.kestra.core.models.flows.Flow) Template(io.kestra.core.tasks.flows.Template) InternalException(io.kestra.core.exceptions.InternalException) TimeoutException(java.util.concurrent.TimeoutException) InternalException(io.kestra.core.exceptions.InternalException) Flow(io.kestra.core.models.flows.Flow) TimeoutException(java.util.concurrent.TimeoutException) InternalException(io.kestra.core.exceptions.InternalException)

Aggregations

InternalException (io.kestra.core.exceptions.InternalException)1 Flow (io.kestra.core.models.flows.Flow)1 Executor (io.kestra.core.runners.Executor)1 FlowExecutorInterface (io.kestra.core.runners.FlowExecutorInterface)1 TaskDefaultService (io.kestra.core.services.TaskDefaultService)1 Template (io.kestra.core.tasks.flows.Template)1 Await (io.kestra.core.utils.Await)1 Duration (java.time.Duration)1 TimeoutException (java.util.concurrent.TimeoutException)1 Slf4j (lombok.extern.slf4j.Slf4j)1 ValueTransformerWithKey (org.apache.kafka.streams.kstream.ValueTransformerWithKey)1 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1