@@ -0,0 +1,1842 @@
+package com.hubspot.singularity.helpers;%0A%0Aimport com.google.inject.Inject;%0Aimport com.hubspot.singularity.SingularityPendingTaskId;%0Aimport com.hubspot.singularity.config.SingularityConfiguration;%0Aimport com.hubspot.singularity.data.TaskManager;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.concurrent.ConcurrentHashMap;%0Aimport java.util.concurrent.ConcurrentMap;%0Aimport java.util.stream.Collectors;%0A%0Apublic class TaskLagGuardrail %7B%0A  private final TaskManager taskManager;%0A  private final SingularityConfiguration configuration;%0A  private ConcurrentMap%3CString, Integer%3E lateTasksByRequestId;%0A  private long lastUpdate;%0A%0A  @Inject%0A  public TaskLagGuardrail(%0A    SingularityConfiguration configuration,%0A    TaskManager taskManager%0A  ) %7B%0A    this.configuration = configuration;%0A    this.taskManager = taskManager;%0A    this.lateTasksByRequestId = new ConcurrentHashMap%3C%3E();%0A    this.lastUpdate = 0;%0A  %7D%0A%0A  public boolean isLagged(String requestId) %7B%0A    updateLateTasksByRequestId();%0A    return lateTasksByRequestId.containsKey(requestId);%0A  %7D%0A%0A  private void updateLateTasksByRequestId() %7B%0A    long now = System.currentTimeMillis();%0A    if (now - lastUpdate %3E 1000L * configuration.getRequestCacheTtl()) %7B%0A      List%3CSingularityPendingTaskId%3E allPendingTaskIds = taskManager.getPendingTaskIds();%0A      this.lateTasksByRequestId =%0A        allPendingTaskIds%0A          .stream()%0A          .filter(%0A            p -%3E%0A              now -%0A              p.getNextRunAt() %3E%0A              configuration.getDeltaAfterWhichTasksAreLateMillis()%0A          )%0A          .collect(%0A            Collectors.toConcurrentMap(%0A              SingularityPendingTaskId::getRequestId,%0A              p -%3E 1,%0A              Integer::sum%0A            )%0A          );%0A      this.lastUpdate = System.currentTimeMillis();%0A    %7D%0A  %7D%0A%7D%0A

create task lag guardrail for request lock users