package com.hubspot.singularity;

import java.util.List;

public class SingularityScheduledTasksInfo {
  private final int numLateTasks;
  private final int numFutureTasks;
  private final long maxTaskLag;

  private SingularityScheduledTasksInfo(int numLateTasks, int numFutureTasks, long maxTaskLag) {
    this.numLateTasks = numLateTasks;
    this.numFutureTasks = numFutureTasks;
    this.maxTaskLag = maxTaskLag;
  }

  public int getNumLateTasks() {
    return numLateTasks;
  }

  public int getNumFutureTasks() {
    return numFutureTasks;
  }

  public long getMaxTaskLag() {
    return maxTaskLag;
  }

  public static SingularityScheduledTasksInfo getInfo(List<SingularityPendingTaskId> pendingTaskIds) {
    final long now = System.currentTimeMillis();

    int numLateTasks = 0;
    int numFutureTasks = 0;
    long maxTaskLag = 0;

    for (SingularityPendingTaskId pendingTaskId : pendingTaskIds) {
      if (pendingTaskId.getNextRunAt() <= now) {
        numLateTasks++;
      } else {
        numFutureTasks++;
      }

      if (now - pendingTaskId.getNextRunAt() > maxTaskLag) {
        maxTaskLag = now - pendingTaskId.getNextRunAt();
      }
    }

    return new SingularityScheduledTasksInfo(numLateTasks, numFutureTasks, maxTaskLag);
  }
}

@@ -198,16 +198,48 @@
 TaskLag;
+%0A  private final long timestamp;
 %0A%0A  priv
@@ -317,32 +317,48 @@
  long maxTaskLag
+, long timestamp
 ) %7B%0A    this.num
@@ -451,32 +451,64 @@
 g = maxTaskLag;%0A
+    this.timestamp = timestamp;%0A
   %7D%0A%0A  public in
@@ -682,24 +682,82 @@
 skLag;%0A  %7D%0A%0A
+  public long getTimestamp() %7B%0A    return timestamp;%0A  %7D%0A%0A
   public sta
@@ -855,24 +855,38 @@
     
-final long now =
+return getInfo(pendingTaskIds,
  Sys
@@ -908,18 +908,142 @@
 Millis()
+)
 ;%0A
+  %7D%0A%0A  public static SingularityScheduledTasksInfo getInfo(List%3CSingularityPendingTaskId%3E pendingTaskIds, long timestamp) %7B
 %0A    int
@@ -1225,19 +1225,25 @@
 At() %3C= 
-now
+timestamp
 ) %7B%0A    
@@ -1322,19 +1322,25 @@
     if (
-now
+timestamp
  - pendi
@@ -1404,11 +1404,17 @@
 g = 
-now
+timestamp
  - p
@@ -1542,16 +1542,27 @@
 xTaskLag
+, timestamp
 );%0A  %7D%0A%7D

include timestamp