This commit is contained in:
Lucio Lelii 2025-04-14 17:03:44 +02:00
parent 16a104b342
commit e1788a86c2
4 changed files with 36 additions and 11 deletions

View File

@ -23,7 +23,6 @@ public class ExecutionService {
public ExecutionObject createExecution(FlowEntity flow) {
ExecutionObject execObject = transformerService.transform(flow.getFlow());
executions.put(execObject.getId(), execObject);
return execObject;
}
@ -43,8 +42,14 @@ public class ExecutionService {
public ExecutionObject prepareInput(String id, String key, Object input) {
ExecutionObject eo = getExecution(id);
if (eo == null) throw new IllegalArgumentException("Execution with id "+id+" not found");
if (eo.getContext().getStatus().isInitState()) {
throw new IllegalStateException("Execution with id "+id+" is not in initialization status (CURRENT STATUS is "+eo.getContext().getStatus()+")");
}
eo.getContext().setStatus(Status.INITIALIZING);
eo.getStartStep().inputReady(key, input);
eo.getContext().addInput(key, input);
if (eo.getStartStep().areAllInputsReady()) {
eo.getContext().setStatus(Status.READY);
}
@ -55,7 +60,7 @@ public class ExecutionService {
ExecutionObject eo = getExecution(id);
if (eo == null) throw new IllegalArgumentException("Execution with id "+id+" not found");
if (eo.getContext().getStatus() != Status.READY) {
throw new IllegalStateException("Execution with id "+id+" is not ready");
throw new IllegalStateException("Execution with id "+id+" is not in READY status (CURRENT STATUS is "+eo.getContext().getStatus()+")");
}
eo.getStartStep().startExecution();
eo.getContext().setStatus(Status.RUNNING);

View File

@ -40,8 +40,6 @@ public class ExecutionObject implements InputReadyListener {
@JsonIgnore
ExecutionStep endStep;
@JsonIgnore
Map<String, Object> inputs = new HashMap<>();
public ExecutionObject(Flow flow) {
this.flow = flow;

View File

@ -2,10 +2,14 @@ package it.cnr.isti.workflow.manager.executors.ai.services;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import java.util.Map;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
@ -17,7 +21,9 @@ public class OpenRouterService {
private static final String OpenRouter_URL = "https://openrouter.ai/api/v1/chat/completions";
public OpenRouterService(WebClient.Builder webClientBuilder) {
this.webClientBuilder = webClientBuilder;
HttpClient client = HttpClient.create()
.responseTimeout(Duration.ofMinutes(2));
this.webClientBuilder = webClientBuilder.clientConnector(new ReactorClientHttpConnector(client));
}
public void setApiKey(String apiKey) {

View File

@ -14,14 +14,26 @@ import lombok.Setter;
public class ExecutionContext {
public enum Status {
CREATED,
INITIALIZING,
READY,
RUNNING,
SUCCESS,
ERROR
CREATED(true),
INITIALIZING(true),
READY(true),
RUNNING(true),
SUCCESS(true),
ERROR(true);
private boolean initState;
Status(boolean initState) {
this.initState = initState;
}
public boolean isInitState() {
return initState;
}
}
Map<String, Object> inputs = new HashMap<>();
@Setter
Map<String, Object> result = null;
@ -44,6 +56,10 @@ public class ExecutionContext {
this.endTime = System.currentTimeMillis();
}
}
public void addInput(String key, Object value) {
this.inputs.put(key, value);
}
}