Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll PRs even after they're overdue #20

Merged
merged 1 commit into from May 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/lib/PullRequestCheckpointsSummary.scala
Expand Up @@ -15,11 +15,13 @@ import play.api.Logger
import scala.util.Try

case class PRCheckpointState(statusByCheckpoint: Map[String, PullRequestCheckpointStatus]) {
def hasStateForCheckpointsWhichHaveAllBeenSeen = statusByCheckpoint.nonEmpty && all(Seen)
val states = statusByCheckpoint.values.toSet

def all(s: PullRequestCheckpointStatus) = statusByCheckpoint.values.forall(_ == s)
val hasStateForCheckpointsWhichHaveAllBeenSeen = states == Set(Seen)

def has(s: PullRequestCheckpointStatus) = statusByCheckpoint.values.exists(_ == s)
def all(s: PullRequestCheckpointStatus) = states.forall(_ == s)

def has(s: PullRequestCheckpointStatus) = states.contains(s)

def changeFrom(oldState: PRCheckpointState) =
(statusByCheckpoint.toSet -- oldState.statusByCheckpoint.toSet).toMap
Expand Down Expand Up @@ -61,8 +63,6 @@ case class PullRequestCheckpointsSummary(
val checkpointsByState: Map[PullRequestCheckpointStatus, Set[Checkpoint]] =
checkpointStatuses.statusByCheckpoint.groupBy(_._2).mapValues(_.keySet.map(tuple => snapshotsByName(tuple).checkpoint))

val hasPendingCheckpoints = checkpointsByState.get(Pending).exists(_.nonEmpty)

val soonestPendingCheckpointOverdueTime: Option[Instant] =
checkpointsByState.get(Pending).map(_.map(_.details.overdue).min).map(new Instant(pr.getMergedAt) + _.standardDuration)

Expand Down
4 changes: 2 additions & 2 deletions app/lib/ScanScheduler.scala
Expand Up @@ -31,13 +31,13 @@ class ScanScheduler(repoFullName: RepoFullName,
case Success(summaries) =>
Logger.info(s"$selfScanScheduler : ${summaries.size} summaries for ${repoFullName.text}:\n${summaries.map(s => s"#${s.pr.getNumber} ${s.stateChange}").mkString("\n")}")

val scanTimeForPendingOpt = summaries.find(_.hasPendingCheckpoints).map(_ => Instant.now + 1.minute)
val scanTimeForUnseenOpt = summaries.find(!_.checkpointStatuses.all(Seen)).map(_ => Instant.now + 1.minute)

val overdueTimes = summaries.collect {
case summary => summary.soonestPendingCheckpointOverdueTime
}.flatten

val candidateFollowUpScanTimes = overdueTimes ++ scanTimeForPendingOpt
val candidateFollowUpScanTimes = overdueTimes ++ scanTimeForUnseenOpt

if (candidateFollowUpScanTimes.nonEmpty) {
val earliestCandidateScanTime: Instant = candidateFollowUpScanTimes.min
Expand Down