Search in sources :

Example 1 with FlowListenersInterface

use of io.kestra.core.services.FlowListenersInterface in project kestra by kestra-io.

the class FlowListenersRestoreCommand method call.

@Override
public Integer call() throws Exception {
    super.call();
    FlowListenersInterface flowListeners = applicationContext.getBean(FlowListenersInterface.class);
    AtomicReference<ZonedDateTime> lastTime = new AtomicReference<>(ZonedDateTime.now());
    flowListeners.run();
    flowListeners.listen(flows -> {
        long count = flows.stream().filter(flow -> !flow.isDeleted()).count();
        stdOut("Received {0} active flows", count);
        if (count > 0) {
            lastTime.set(ZonedDateTime.now());
        }
    });
    // we can't know when it's over, wait no more flow received
    Await.until(() -> lastTime.get().compareTo(ZonedDateTime.now().minus(this.timeout)) < 0);
    return 0;
}
Also used : Slf4j(lombok.extern.slf4j.Slf4j) ApplicationContext(io.micronaut.context.ApplicationContext) Await(io.kestra.core.utils.Await) Duration(java.time.Duration) ZonedDateTime(java.time.ZonedDateTime) FlowListenersInterface(io.kestra.core.services.FlowListenersInterface) Inject(jakarta.inject.Inject) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractCommand(io.kestra.cli.AbstractCommand) CommandLine(picocli.CommandLine) ZonedDateTime(java.time.ZonedDateTime) AtomicReference(java.util.concurrent.atomic.AtomicReference) FlowListenersInterface(io.kestra.core.services.FlowListenersInterface)

Aggregations

AbstractCommand (io.kestra.cli.AbstractCommand)1 FlowListenersInterface (io.kestra.core.services.FlowListenersInterface)1 Await (io.kestra.core.utils.Await)1 ApplicationContext (io.micronaut.context.ApplicationContext)1 Inject (jakarta.inject.Inject)1 Duration (java.time.Duration)1 ZonedDateTime (java.time.ZonedDateTime)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CommandLine (picocli.CommandLine)1