public void afterDisconnect()

in src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java [76:126]


    public void afterDisconnect(final SlaveComputer computer, final TaskListener listener) {
        // according to jenkins docs could be null in edge cases, check ComputerLauncher.afterDisconnect
        if (computer == null) return;

        // in some multi-thread edge cases cloud could be null for some time, just be ok with that
        final EC2FleetCloud cloud = ((EC2FleetNodeComputer) computer).getCloud();
        if (cloud == null) {
            LOGGER.warning("Edge case cloud is null for computer " + computer.getDisplayName()
                    + " should be autofixed in a few minutes, if no please create issue for plugin");
            return;
        }

        final boolean unexpectedDisconnect = computer.isOffline() && computer.getOfflineCause() instanceof OfflineCause.ChannelTermination;
        if (!cloud.isDisableTaskResubmit() && unexpectedDisconnect) {
            final List<Executor> executors = computer.getExecutors();
            LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName()
                    + " termination,  resubmit");

            for (Executor executor : executors) {
                if (executor.getCurrentExecutable() != null) {
                    executor.interrupt(Result.ABORTED, new EC2TerminationCause(computer.getDisplayName()));

                    final Queue.Executable executable = executor.getCurrentExecutable();
                    // if executor is not idle
                    if (executable != null) {
                        final SubTask subTask = executable.getParent();
                        final Queue.Task task = subTask.getOwnerTask();

                        List<Action> actions = new ArrayList<>();
                        if (executable instanceof Actionable) {
                            actions = ((Actionable) executable).getActions();
                        }

                        Queue.getInstance().schedule2(task, RESCHEDULE_QUIET_PERIOD_SEC, actions);
                        LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName()
                                + " termination, resubmit " + task + " with actions " + actions);
                    }
                }
            }
            LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName()
                    + " termination, resubmit finished");
        } else {
            LOGGER.log(LOG_LEVEL, "Unexpected " + computer.getDisplayName()
                    + " termination but resubmit disabled, no actions, disableTaskResubmit: "
                    + cloud.isDisableTaskResubmit() + ", offline: " + computer.isOffline()
                    + ", offlineCause: " + (computer.getOfflineCause() != null ? computer.getOfflineCause().getClass() : "null"));
        }

        // call parent
        super.afterDisconnect(computer, listener);
    }