asfgit closed pull request #1: MTCGA-002 Build trigger timeout.
URL: https://github.com/apache/ignite-teamcity-bot/pull/1
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
index 4ceedec..7b75223 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServer.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.ci.conf;
 
+import java.util.Objects;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
@@ -24,39 +25,54 @@
  * Created by Дмитрий on 09.11.2017.
  */
 public class ChainAtServer {
-    /** Server ID to access config files within helper */
+    /** Server ID to access config files within helper. */
     @Nullable public String serverId;
 
-    /** Suite identifier by teamcity identification for root chain */
+    /** Suite identifier by teamcity identification for root chain. */
     @Nonnull public String suiteId;
 
     /** Automatic build triggering. */
     @Nullable private Boolean triggerBuild;
 
+    /** Automatic build triggering quiet period in minutes. */
+    @Nullable private Integer triggerBuildQuietPeriod;
+
+    /** {@inheritDoc} */
     @Override public boolean equals(Object o) {
         if (this == o)
             return true;
         if (o == null || getClass() != o.getClass())
             return false;
-
         ChainAtServer server = (ChainAtServer)o;
-
-        if (serverId != null ? !serverId.equals(server.serverId) : 
server.serverId != null)
-            return false;
-        return suiteId.equals(server.suiteId);
+        return Objects.equals(serverId, server.serverId) &&
+            Objects.equals(suiteId, server.suiteId) &&
+            Objects.equals(triggerBuild, server.triggerBuild) &&
+            Objects.equals(triggerBuildQuietPeriod, 
server.triggerBuildQuietPeriod);
     }
 
+    /** {@inheritDoc} */
     @Override public int hashCode() {
-        int result = serverId != null ? serverId.hashCode() : 0;
-        result = 31 * result + suiteId.hashCode();
-        return result;
+        return Objects.hash(serverId, suiteId, triggerBuild, 
triggerBuildQuietPeriod);
     }
 
+    /**
+     * @return Server ID to access config files within helper.
+     */
     @Nullable public String getServerId() {
         return serverId;
     }
 
+    /**
+     * @return {@code True} If automatic build triggering enabled.
+     */
     @Nonnull public boolean isTriggerBuild() {
         return triggerBuild == null ? false : triggerBuild;
     }
+
+    /**
+     * @return Quiet period in minutes between triggering builds or zero if 
period is not set and should be ignored.
+     */
+    @Nonnull public int getTriggerBuildQuietPeriod() {
+        return triggerBuildQuietPeriod == null ? 0 : triggerBuildQuietPeriod;
+    }
 }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServerTracked.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServerTracked.java
index c08c588..d0dbea6 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServerTracked.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/ChainAtServerTracked.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.ci.conf;
 
+import java.util.Objects;
 import javax.annotation.Nonnull;
 
 import static com.google.common.base.Preconditions.checkState;
@@ -44,4 +45,19 @@
 
         return branchForRest;
     }
+
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+        if (!super.equals(o))
+            return false;
+        ChainAtServerTracked tracked = (ChainAtServerTracked)o;
+        return Objects.equals(branchForRest, tracked.branchForRest);
+    }
+
+    @Override public int hashCode() {
+        return Objects.hash(super.hashCode(), branchForRest);
+    }
 }
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 3065e2d..7eb7e7a 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
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import org.apache.ignite.ci.HelperConfig;
 import org.apache.ignite.ci.ITcHelper;
 import org.apache.ignite.ci.ITeamcity;
@@ -56,6 +57,9 @@
     /** */
     private final ITcHelper tcHelper;
 
+    /** */
+    private final Map<ChainAtServerTracked, Long> startTimes = new HashMap<>();
+
     /**
      * @param creds Background credentials provider.
      */
@@ -150,8 +154,31 @@ private void checkQueue(ITeamcity teamcity, 
List<ChainAtServerTracked> chains) t
             }
 
             if (triggerBuild) {
-                for (ChainAtServerTracked chain : chains)
+                for (ChainAtServerTracked chain : chains) {
+                    long curr = System.currentTimeMillis();
+                    long delay = chain.getTriggerBuildQuietPeriod();
+
+                    if (delay > 0) {
+                        Long lastStart = startTimes.get(chain);
+
+                        long minsPassed;
+
+                        if (lastStart != null &&
+                            (minsPassed = TimeUnit.MILLISECONDS.toMinutes(curr 
- lastStart)) < delay) {
+
+                            logger.info("Skip triggering build, timeout has 
not expired " +
+                                    "(server={}, suite={}, branch={}, delay={} 
mins, passed={} mins)",
+                                chain.getServerId(), 
chain.getSuiteIdMandatory(), chain.getBranchForRestMandatory(),
+                                chain.getTriggerBuildQuietPeriod(), 
minsPassed);
+
+                            continue;
+                        }
+                    }
+
+                    startTimes.put(chain, curr);
+
                     teamcity.triggerBuild(chain.suiteId, chain.branchForRest, 
true, false);
+                }
             }
         }
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to