Commits

Richard Warburton  committed cd0113a Merge

Merged in arkangelofkaos/betterrev (pull request #63)

Scheduling regular import from Bitbucket

  • Participants
  • Parent commits a78b176, 0462c30

Comments (0)

Files changed (3)

File betterrev/app/Global.java

 import com.gs.collections.impl.map.mutable.UnifiedMap;
 import models.PullReviewEvent;
 import play.Application;
-import play.utils.crud.GlobalCRUDSettings;
+import play.Logger;
+import play.Play;
 import play.libs.Akka;
+import play.utils.crud.GlobalCRUDSettings;
+import scala.concurrent.duration.Duration;
+import scala.concurrent.duration.FiniteDuration;
 import update.BetterrevActor;
 import update.bitbucket.BitbucketPoller;
 import update.bitbucket.PollBitbucketEvent;
 import update.pullrequest.ImportPullRequestsEvent;
 import update.pullrequest.PullRequestImporter;
 
+import java.util.concurrent.TimeUnit;
+
 import static com.gs.collections.impl.utility.MapIterate.forEachKeyValue;
 
 /**
         super.onStart(app);
         if (!app.isTest()) {
             subscribeActorsToEvents();
-            pollBitbucket();
+            regularlyPollBitbucket();
         }
     }
 
         return Akka.system().eventStream().subscribe(actor, eventClass);
     }
 
-    private void pollBitbucket() {
-        Akka.system().eventStream().publish(new PollBitbucketEvent());
+    private void regularlyPollBitbucket() {
+        long duration = Play.application().configuration().getLong("bitbucket.polling.duration.seconds");
+        FiniteDuration pollingDuration = Duration.create(duration, TimeUnit.SECONDS);
+        Akka.system().scheduler().schedule(Duration.Zero(), pollingDuration, new Runnable() {
+            @Override
+            public void run() {
+                Logger.debug("Publishing new PollBitbucketEvent message.");
+                Akka.system().eventStream().publish(new PollBitbucketEvent());
+            }
+        }, Akka.system().dispatcher());
+
     }
 }

File betterrev/app/update/pullrequest/PullRequestImporter.java

 package update.pullrequest;
 
 import models.*;
-
 import org.codehaus.jackson.JsonNode;
 import org.joda.time.DateTime;
-
 import play.Logger;
 import update.BetterrevActor;
 
                                            updatedOn,
                                            branchName);
         review.save();
-
+        Logger.debug(String.format("Created new pull review - id: %s, bitbucket username: %s", requestId, user.bitbucketUserName));
         publishPullReviewGeneratedEvent(review, "");
-
         return review;
     }
 

File betterrev/conf/application.conf

 # Application
 
 owner=AdoptOpenJDK
-projects=better-test-repo betterrev
+projects=better-test-repo betterrev
+bitbucket.polling.duration.seconds=600