public void saveResult(
      Optional<Integer> statusCode, Optional<String> responseBody, Optional<String> errorMessage) {
    SingularityTaskHealthcheckResult result =
        new SingularityTaskHealthcheckResult(
            statusCode,
            Optional.of(System.currentTimeMillis() - startTime),
            startTime,
            responseBody,
            errorMessage,
            task.getTaskId());

    LOG.trace("Saving healthcheck result {}", result);

    try {
      taskManager.saveHealthcheckResult(result);

      if (result.isFailed()) {
        if (!taskManager.isActiveTask(task.getTaskId().getId())) {
          LOG.trace("Task {} is not active, not re-enqueueing healthcheck", task.getTaskId());
          return;
        }

        healthchecker.enqueueHealthcheck(task);
      } else {
        newTaskChecker.runNewTaskCheckImmediately(task);
      }
    } catch (Throwable t) {
      LOG.error("Caught throwable while saving health check result {}, will re-enqueue", result, t);
      exceptionNotifier.notify(t);

      reEnqueueOrAbort(task);
    }
  }
  private void reEnqueueOrAbort(SingularityTask task) {
    try {
      healthchecker.enqueueHealthcheck(task);
    } catch (Throwable t) {
      LOG.error(
          "Caught throwable while re-enqueuing health check for {}, aborting", task.getTaskId(), t);
      exceptionNotifier.notify(t);

      abort.abort(AbortReason.UNRECOVERABLE_ERROR);
    }
  }