/**
   * Schedules the given configuration.
   *
   * <p>Copied from the {@link
   * DefaultMatrixExecutionStrategyImpl#scheduleConfigurationBuild(hudson.matrix.MatrixBuild.MatrixBuildExecution,
   * hudson.matrix.MatrixConfiguration)}
   *
   * @param execution Contains information about the general build, including the listener used to
   *     log queue blockage.
   * @param configuration The configuration to schedule.
   * @param upstreamCause The cause of the build. Will either be an {@link
   *     hudson.model.Cause.UpstreamCause} or {@link
   *     com.attask.jenkins.healingmatrixproject.SelfHealingCause}.
   */
  private void scheduleConfigurationBuild(
      MatrixBuild.MatrixBuildExecution execution,
      MatrixConfiguration configuration,
      Cause.UpstreamCause upstreamCause)
      throws InterruptedException {
    MatrixBuild build = (MatrixBuild) execution.getBuild();
    execution
        .getListener()
        .getLogger()
        .println(Messages.MatrixBuild_Triggering(ModelHyperlinkNote.encodeTo(configuration)));

    // filter the parent actions for those that can be passed to the individual jobs.
    List<MatrixChildAction> childActions = Util.filter(build.getActions(), MatrixChildAction.class);

    BuildListener listener = execution.getListener();
    while (!configuration.scheduleBuild(childActions, upstreamCause)) {
      String msg = "Unable to schedule build " + configuration.getFullDisplayName() + ". Retrying.";
      listener.error(msg);
      Thread.sleep(500);
    }
  }