This is an automated email from the ASF dual-hosted git repository.
sk0x50 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
The following commit(s) were added to refs/heads/master by this push:
new 3a0986e7 IGNITE-36129 Bot should send a message to the Slack channel
on itself start and stop. Fixes #194
3a0986e7 is described below
commit 3a0986e711b523c6685c40dc13cf00ab6a84b028
Author: Sergey Uttsel <[email protected]>
AuthorDate: Mon Feb 20 17:59:31 2023 +0200
IGNITE-36129 Bot should send a message to the Slack channel on itself start
and stop. Fixes #194
Signed-off-by: Slava Koptilin <[email protected]>
---
.../java/org/apache/ignite/ci/web/CtxListener.java | 30 +++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
index 25494bcd..b1d0cc59 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
@@ -32,7 +32,11 @@ import org.apache.ignite.ci.tcbot.TcBotWebAppModule;
import org.apache.ignite.ci.tcbot.issue.IssueDetector;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptor;
import org.apache.ignite.tcbot.engine.cleaner.Cleaner;
+import org.apache.ignite.tcbot.engine.conf.INotificationChannel;
+import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
+import org.apache.ignite.tcbot.engine.conf.NotificationsConfig;
import org.apache.ignite.tcbot.engine.pool.TcUpdatePool;
+import org.apache.ignite.tcbot.notify.ISlackSender;
import org.apache.ignite.tcbot.persistence.scheduler.IScheduler;
import org.apache.ignite.tcservice.http.TeamcityRecorder;
import org.slf4j.Logger;
@@ -61,6 +65,8 @@ public class CtxListener implements ServletContextListener {
final ServletContext ctx = sctxEvt.getServletContext();
ctx.setAttribute(INJECTOR, injector);
+
+ sendMessageToSlackChannel("TeamCity Bot is started!", ctx);
}
/**
@@ -82,6 +88,8 @@ public class CtxListener implements ServletContextListener {
@Override public void contextDestroyed(ServletContextEvent sctxEvt) {
final ServletContext ctx = sctxEvt.getServletContext();
+ sendMessageToSlackChannel("TeamCity Bot is stopped!", ctx);
+
Injector injector = getInjector(ctx);
try {
@@ -125,5 +133,25 @@ public class CtxListener implements ServletContextListener
{
logger.error("Exception during shutdown: " + e.getMessage(),
e);
}
}
-}
+ private void sendMessageToSlackChannel(String msg, ServletContext ctx) {
+ try {
+ ISlackSender slackSender =
CtxListener.getInjector(ctx).getInstance(ISlackSender.class);
+
+ ITcBotConfig tcBotConfig =
CtxListener.getInjector(ctx).getInstance(ITcBotConfig.class);
+
+ NotificationsConfig notifications = tcBotConfig.notifications();
+
+ for (INotificationChannel channel : notifications.channels()) {
+ if (channel.slack() != null && channel.slack().startsWith("#"))
+ slackSender.sendMessage(channel.slack(), msg,
notifications);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+
+ if (logger != null)
+ logger.error("Exception during sending message to the slack
channel: " + e.getMessage(), e);
+ }
+ }
+}