Skip to content
Permalink
Browse files
Improved exception handling on periodic check servers queue failed. A…
…dded slack notification. #172

Signed-off-by: Ivan Rakov <ivan.glukos@gmail.com>
  • Loading branch information
sergeyuttsel authored and glukos committed Aug 3, 2020
1 parent 82c3594 commit b0b358058c787108d290d380ca6791c0f1a64986
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
@@ -47,7 +47,7 @@ allprojects {
jettyVer = '9.4.12.v20180830'

// ignVer = '2.7.0'
ignVer = '2.8.0'
ignVer = '2.8.1'
// ignVer = '2.7.0-SNAPSHOT'

guavaVer = '26.0-jre'
@@ -30,7 +30,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import org.apache.ignite.ci.teamcity.ignited.BuildRefCompacted;
@@ -43,6 +42,8 @@
import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
import org.apache.ignite.tcbot.engine.conf.ITrackedBranch;
import org.apache.ignite.tcbot.engine.conf.ITrackedChain;
import org.apache.ignite.tcbot.engine.conf.NotificationsConfig;
import org.apache.ignite.tcbot.notify.ISlackSender;
import org.apache.ignite.tcbot.persistence.IStringCompactor;
import org.apache.ignite.tcignited.ITeamcityIgnited;
import org.apache.ignite.tcignited.ITeamcityIgnitedProvider;
@@ -53,6 +54,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.stream.Collectors.toList;

/**
* Trigger build if half of agents are available and there is no self-triggered builds in build queue.
*/
@@ -79,6 +82,9 @@ public class CheckQueueJob implements Runnable {
/** */
@Inject private ITcBotConfig cfg;

/** */
@Inject private ISlackSender slackSender;

/** */
private final Map<ITrackedChain, Long> startTimes = new HashMap<>();

@@ -94,10 +100,26 @@ public void init(ITcBotUserCreds creds) {
try {
runEx();
}
catch (Exception e) {
catch (Throwable e) {
e.printStackTrace();

logger.error("Check Queue periodic check failed: " + e.getMessage(), e);

NotificationsConfig notifications = cfg.notifications();

String msg = ":warning: Periodic check servers queue and build triggering failed";

notifications.channels().forEach(channel -> {
String chName = channel.slack();

if (chName != null && chName.startsWith("#"))
try {
slackSender.sendMessage(chName, msg, notifications);
}
catch (Exception ex) {
logger.warn("Unable to notify address [" + chName + "] about periodic check queue failure", e);
}
});
}
}

@@ -136,7 +158,7 @@ protected String runEx() {
List<ITrackedChain> chainsAll = entry.getValue();
List<ITrackedChain> chains = chainsAll.stream()
.filter(c -> Objects.equals(c.serverCode(), srvCode))
.collect(Collectors.toList());
.collect(toList());

srvsChecked++;

0 comments on commit b0b3580

Please sign in to comment.