<P> DaemonResponse<P> reapChild(DaemonTask task) throws InterruptedException { DaemonTask childTask = children.stream() .filter(c -> c.getUuid().equals(task.getUuid())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Child " + task + " does not belong to this task " + this + "")); // Spin due to spurious wakeups while (!childTask.getState().isTerminal()) { try { synchronized (childTask) { childTask.wait(); } } catch (InterruptedException e) { throw e; } } TaskRepository.getTask(childTask.getUuid()); log.info(this + "Collected child task " + childTask + " with state " + childTask.getState()); if (childTask.getResponse() == null) { throw new RuntimeException("Child response may not be null."); } return childTask.getResponse(); }
@Override public void run() { long sleepTime = endTime - System.currentTimeMillis(); while (sleepTime > 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException ignored) { } sleepTime = endTime - System.currentTimeMillis(); } switch (target.getState()) { case NOT_STARTED: case RUNNING: log.warn("Interrupting task " + target + " that timed out after " + (endTime - startTime) + " millis."); target.timeout(); break; case TIMED_OUT: case INTERRUPTED: case FAILED: case SUCCEEDED: log.info("Interrupter has no work to do, " + target + " already completed."); break; } try { Thread.sleep(DELETE_TASK_INFO_WINDOW); } catch (InterruptedException ignored) { } deleteTaskInfo(target.getUuid()); } }
ShallowTaskInfo(DaemonTask task) { this.uuid = task.getUuid(); this.name = task.getName(); this.state = task.getState(); this.fatalException = task.getFatalError(); this.jobs = task.getRunningJobs(); if (!task.getEvents().isEmpty()) { this.lastEvent = task.getEvents().get(task.getEvents().size() - 1).toString(); } this.children = (List<String>) task.getChildren() .stream() .map(c -> c.toString()) .collect(Collectors.toList()); } }
static public <C, T> DaemonTask<C, T> submitTask(Supplier<DaemonResponse<T>> runner, String name, long timeout) { DaemonTask<C, T> task = new DaemonTask<>(name, timeout); String uuid = task.getUuid(); log.info("Scheduling task " + task); Runnable r = () -> {
public static <C, T> T get(DaemonTask<C, T> task) { int lastTaskCount = 0; task = Daemon.getTask(task.getUuid()); Set<String> loggedEvents = new HashSet<>(); while (!task.getState().isTerminal()) { updateCycle(); if (interrupted) { Daemon.interruptTask(task.getUuid()); throw TaskKilledException.interrupted(new InterruptedException("Interrupted by user")); task = Daemon.getTask(task.getUuid());
public static <C, T> T get(DaemonTask<C, T> task) { int lastTaskCount = 0; task = Daemon.getTask(task.getUuid()); Set<String> loggedEvents = new HashSet<>(); while (!task.getState().isTerminal()) { updateCycle(); if (interrupted) { Daemon.interruptTask(task.getUuid()); throw TaskKilledException.interrupted(new InterruptedException("Interrupted by user")); task = Daemon.getTask(task.getUuid());