public FailedTestAndBuildProblemsDispatcher()

in src/main/java/jetbrains/buildServer/investigationsAutoAssigner/FailedTestAndBuildProblemsDispatcher.java [50:141]


  public FailedTestAndBuildProblemsDispatcher(@NotNull final BuildServerListenerEventDispatcher buildServerListenerEventDispatcher,
                                              @NotNull final FailedTestAndBuildProblemsProcessor processor,
                                              @NotNull final DelayedAssignmentsProcessor delayedAssignmentsProcessor,
                                              @NotNull final AggregationLogger aggregationLogger,
                                              @NotNull final StatisticsReporter statisticsReporter,
                                              @NotNull final CustomParameters customParameters,
                                              @NotNull final BuildsManager buildsManager,
                                              @NotNull final ServerResponsibility serverResponsibility) {
    myProcessor = processor;
    myDelayedAssignmentsProcessor = delayedAssignmentsProcessor;
    myAggregationLogger = aggregationLogger;
    myStatisticsReporter = statisticsReporter;
    myCustomParameters = customParameters;
    myBuildsManager = buildsManager;
    myServerResponsibility = serverResponsibility;
    myExecutor = ExecutorsFactory.newFixedScheduledDaemonExecutor(Constants.BUILD_FEATURE_TYPE, 1);
    myExecutor.scheduleWithFixedDelay(this::processBrokenBuildsOneThread,
                                      CustomParameters.getProcessingDelayInSeconds(),
                                      CustomParameters.getProcessingDelayInSeconds(),
                                      TimeUnit.SECONDS);

    buildServerListenerEventDispatcher.addListener(new BuildServerAdapter() {
      @Override
      public void buildProblemsChanged(@NotNull SBuild sBuild,
                                       @NotNull List<BuildProblemData> before,
                                       @NotNull List<BuildProblemData> after) {
        if (!canSendNotifications()) return;

        if (myFailedBuilds.contains(sBuild.getBuildId()) || shouldIgnore(sBuild)) {
          return;
        }

        myFailedBuilds.add(sBuild.getBuildId());
      }

      @Override
      public void buildInterrupted(@NotNull final SRunningBuild build) {
        myFailedBuilds.remove(build.getBuildId());
      }

      @Override
      public void buildFinished(@NotNull SRunningBuild build) {
        if (shouldIgnore(build) || !canSendNotifications()) {
          myFailedBuilds.remove(build.getBuildId());
          return;
        }

        try {
          scheduleDelayedAssignmentProcessing(build);

          if (myFailedBuilds.remove(build.getBuildId())) {
            scheduleFinishedBuildProcessing(build);
          }
        } catch (RejectedExecutionException e) {
          LOGGER.infoAndDebugDetails("Could not schedule automatic assignment investigations for the finishing build " + build, e);
          myFailedBuilds.remove(build.getBuildId());
        }
      }

      @Override
      public void responsibleChanged(@NotNull final SProject project,
                                     @NotNull final Collection<TestName> testNames,
                                     @NotNull final ResponsibilityEntry entry,
                                     final boolean isUserAction) {
        if (isUserAction && shouldBeReportedAsWrong(entry)) {
          myStatisticsReporter.reportWrongInvestigation(testNames.size());
        }
      }

      private boolean shouldBeReportedAsWrong(@Nullable final ResponsibilityEntry entry) {
        return entry != null &&
               entry.getReporterUser() != null &&
               (entry.getState() == ResponsibilityEntry.State.GIVEN_UP ||
                entry.getState() == ResponsibilityEntry.State.TAKEN) &&
               entry.getComment().startsWith(Constants.ASSIGN_DESCRIPTION_PREFIX);
      }

      @Override
      public void responsibleChanged(@NotNull final SProject project,
                                     @NotNull final Collection<BuildProblemInfo> buildProblems,
                                     @Nullable final ResponsibilityEntry entry) {
        if (shouldBeReportedAsWrong(entry)) {
          myStatisticsReporter.reportWrongInvestigation(buildProblems.size());
        }
      }

      @Override
      public void serverShutdown() {
        ThreadUtil.shutdownGracefully(myExecutor, "Investigator-Auto-Assigner Daemon");
      }
    });
  }