This is an automated email from the ASF dual-hosted git repository.
dpavlov 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 0b157aa Add option to disable auto-triggering bot during working
hours (#157)
0b157aa is described below
commit 0b157aa8c9c4a8d804564afe48b87bffb327e707
Author: Mirza Aliev <[email protected]>
AuthorDate: Tue Dec 24 14:56:32 2019 +0300
Add option to disable auto-triggering bot during working hours (#157)
---
.../org/apache/ignite/ci/jobs/CheckQueueJob.java | 36 ++++++++++++++++++++++
.../ignite/tcbot/common/conf/ITcServerConfig.java | 11 +++++++
.../ignite/tcbot/engine/conf/TcServerConfig.java | 17 ++++++++++
3 files changed, 64 insertions(+)
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
index fff05e3..4f83fad 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
@@ -19,7 +19,10 @@ package org.apache.ignite.ci.jobs;
import com.google.common.base.Strings;
import java.text.MessageFormat;
+import java.time.DayOfWeek;
import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -123,6 +126,13 @@ public class CheckQueueJob implements Runnable {
for (Map.Entry<String, List<ITrackedChain>> entry :
chainsBySrv.entrySet()) {
String srvCode = entry.getKey();
+ if (autoTriggerDisabledForWorkingHours(srvCode)) {
+ final String msg = "Automatic build triggering was disabled
during working hours.";
+ logger.info(msg);
+
+ return msg;
+ }
+
List<ITrackedChain> chainsAll = entry.getValue();
List<ITrackedChain> chains = chainsAll.stream()
.filter(c -> Objects.equals(c.serverCode(), srvCode))
@@ -327,4 +337,30 @@ public class CheckQueueJob implements Runnable {
return chainsBySrv;
}
+
+ /**
+ * @param srvCode Server code.
+ * @return {@code true} if auto-triggering disabled for working hours.
+ */
+ private boolean autoTriggerDisabledForWorkingHours(String srvCode) {
+
+ DayOfWeek curDayOfWeek = LocalDate.now().getDayOfWeek();
+
+ if (curDayOfWeek == DayOfWeek.SATURDAY || curDayOfWeek ==
DayOfWeek.SUNDAY)
+ return false;
+
+ String startTime =
cfg.getTeamcityConfig(srvCode).autoTriggeringBuildDisabledStartTime();
+
+ String endTime =
cfg.getTeamcityConfig(srvCode).autoTriggeringBuildDisabledEndTime();
+
+ if (startTime == null || endTime == null)
+ return false;
+
+ LocalTime now = LocalTime.now();
+
+ if (now.isAfter(LocalTime.parse(startTime)) &&
now.isBefore(LocalTime.parse(endTime)))
+ return true;
+
+ return false;
+ }
}
diff --git
a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java
b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java
index 396a8bf..d35f33c 100644
---
a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java
+++
b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java
@@ -16,6 +16,7 @@
*/
package org.apache.ignite.tcbot.common.conf;
+import java.time.format.DateTimeFormatter;
import org.checkerframework.checker.nullness.qual.NonNull;
import javax.annotation.Nullable;
@@ -72,4 +73,14 @@ public interface ITcServerConfig {
* @return set of suite codes (build type IDs), failures in which should
be threated as critical and notified.
*/
@NonNull public Collection<String> trustedSuites();
+
+ /**
+ * @return Time as auto-triggering build is disabled. {@link
DateTimeFormatter.ISO_LOCAL_TIME} must be used.
+ */
+ @Nullable String autoTriggeringBuildDisabledStartTime();
+
+ /**
+ * @return Time as auto-triggering build is enabled. {@link
DateTimeFormatter.ISO_LOCAL_TIME} must be used.
+ */
+ @Nullable String autoTriggeringBuildDisabledEndTime();
}
diff --git
a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java
b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java
index afd360a..3726c17 100644
---
a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java
+++
b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java
@@ -17,6 +17,7 @@
package org.apache.ignite.tcbot.engine.conf;
import com.google.common.base.Strings;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -69,6 +70,12 @@ public class TcServerConfig implements ITcServerConfig {
/** Additional service code to check access before allowing accessing this
service. */
private String additionalServiceToCheckAccess;
+ /** Time as auto-triggering build is disabled. {@link
DateTimeFormatter.ISO_LOCAL_TIME} must be used. */
+ @Nullable private String autoTriggeringBuildDisabledStartTime;
+
+ /** Time as auto-triggering build is enabled. {@link
DateTimeFormatter.ISO_LOCAL_TIME} must be used. */
+ @Nullable private String autoTriggeringBuildDisabledEndTime;
+
public TcServerConfig() {
}
@@ -164,4 +171,14 @@ public class TcServerConfig implements ITcServerConfig {
return this;
}
+
+ /** {@inheritDoc} */
+ public String autoTriggeringBuildDisabledStartTime() {
+ return autoTriggeringBuildDisabledStartTime;
+ }
+
+ /** {@inheritDoc} */
+ public String autoTriggeringBuildDisabledEndTime() {
+ return autoTriggeringBuildDisabledEndTime;
+ }
}