use of io.micronaut.scheduling.annotation.ExecuteOn in project kestra by kestra-io.
the class ExecutionController method replay.
/**
* Create a new execution from an old one and start it from a specified task run id
*
* @param executionId the origin execution id to clone
* @param taskRunId the reference taskRun id
* @return the restarted execution
*/
@ExecuteOn(TaskExecutors.IO)
@Post(uri = "executions/{executionId}/replay", produces = MediaType.TEXT_JSON)
public Execution replay(String executionId, @Nullable @QueryValue(value = "taskRunId") String taskRunId, @Nullable @QueryValue(value = "revision") Integer revision) throws Exception {
Optional<Execution> execution = executionRepository.findById(executionId);
if (execution.isEmpty()) {
return null;
}
this.controlRevision(execution.get(), revision);
Execution replay = executionService.replay(execution.get(), taskRunId, revision);
executionQueue.emit(replay);
eventPublisher.publishEvent(new CrudEvent<>(replay, CrudEventType.CREATE));
return replay;
}
use of io.micronaut.scheduling.annotation.ExecuteOn in project kestra by kestra-io.
the class ExecutionController method restart.
/**
* Restart a new execution from an old one
*
* @param executionId the origin execution id to clone
* @return the restarted execution
*/
@ExecuteOn(TaskExecutors.IO)
@Post(uri = "executions/{executionId}/restart", produces = MediaType.TEXT_JSON)
public Execution restart(String executionId, @Nullable @QueryValue(value = "revision") Integer revision) throws Exception {
Optional<Execution> execution = executionRepository.findById(executionId);
if (execution.isEmpty()) {
return null;
}
this.controlRevision(execution.get(), revision);
Execution restart = executionService.restart(execution.get(), revision);
executionQueue.emit(restart);
eventPublisher.publishEvent(new CrudEvent<>(restart, CrudEventType.UPDATE));
return restart;
}
use of io.micronaut.scheduling.annotation.ExecuteOn in project kestra by kestra-io.
the class ExecutionController method follow.
/**
* Trigger a new execution for current flow and follow execution
*
* @param executionId The execution id to follow
* @return execution sse event
*/
@ExecuteOn(TaskExecutors.IO)
@Get(uri = "executions/{executionId}/follow", produces = MediaType.TEXT_EVENT_STREAM)
public Flowable<Event<Execution>> follow(String executionId) {
AtomicReference<Runnable> cancel = new AtomicReference<>();
return Flowable.<Event<Execution>>create(emitter -> {
// already finished execution
Execution execution = Await.until(() -> executionRepository.findById(executionId).orElse(null), Duration.ofMillis(500));
Flow flow = flowRepository.findByExecution(execution);
if (conditionService.isTerminatedWithListeners(flow, execution)) {
emitter.onNext(Event.of(execution).id("end"));
emitter.onComplete();
return;
}
// emit the repository one first in order to wait the queue connections
emitter.onNext(Event.of(execution).id("progress"));
// consume new value
Runnable receive = this.executionQueue.receive(current -> {
if (current.getId().equals(executionId)) {
emitter.onNext(Event.of(current).id("progress"));
if (conditionService.isTerminatedWithListeners(flow, current)) {
emitter.onNext(Event.of(current).id("end"));
emitter.onComplete();
}
}
});
cancel.set(receive);
}, BackpressureStrategy.BUFFER).doOnCancel(() -> {
if (cancel.get() != null) {
cancel.get().run();
}
}).doOnComplete(() -> {
if (cancel.get() != null) {
cancel.get().run();
}
});
}
use of io.micronaut.scheduling.annotation.ExecuteOn in project kestra by kestra-io.
the class ExecutionController method file.
/**
* Download file binary from uri parameter
*
* @param path The file URI to return
* @return data binary content
*/
@ExecuteOn(TaskExecutors.IO)
@Get(uri = "executions/{executionId}/file", produces = MediaType.APPLICATION_OCTET_STREAM)
public HttpResponse<StreamedFile> file(String executionId, @QueryValue(value = "path") URI path) throws IOException, URISyntaxException {
HttpResponse<StreamedFile> httpResponse = this.validateFile(executionId, path, "/api/v1/executions/{executionId}/file?path=" + path);
if (httpResponse != null) {
return httpResponse;
}
InputStream fileHandler = storageInterface.get(path);
return HttpResponse.ok(new StreamedFile(fileHandler, MediaType.APPLICATION_OCTET_STREAM_TYPE).attach(FilenameUtils.getName(path.toString())));
}
use of io.micronaut.scheduling.annotation.ExecuteOn in project kestra by kestra-io.
the class ExecutionController method trigger.
/**
* Trigger a new execution for current flow
*
* @param namespace The flow namespace
* @param id The flow id
* @return execution created
*/
@ExecuteOn(TaskExecutors.IO)
@Post(uri = "executions/trigger/{namespace}/{id}", produces = MediaType.TEXT_JSON, consumes = MediaType.MULTIPART_FORM_DATA)
public Execution trigger(String namespace, String id, @Nullable Map<String, String> inputs, @Nullable Publisher<StreamingFileUpload> files) {
Optional<Flow> find = flowRepository.findById(namespace, id);
if (find.isEmpty()) {
return null;
}
Execution current = runnerUtils.newExecution(find.get(), (flow, execution) -> runnerUtils.typedInputs(flow, execution, inputs, files));
executionQueue.emit(current);
eventPublisher.publishEvent(new CrudEvent<>(current, CrudEventType.CREATE));
return current;
}
Aggregations