   end
 
   defp queue_delay_ms(time) do
-    (time - @expiring_soon_in_seconds) * @milliseconds_in_seconds
+    remaining_time = min(time, (time - @expiring_soon_in_seconds))
+    remaining_time * @milliseconds_in_seconds
   end
 
 end

  end

  def queue_for_refresh(team) do
    e = expires_in_unix(team)
    n = :os.system_time(:seconds)
    limit = @expiring_soon_in_seconds
    diff = expires_in_unix(team) - :os.system_time(:seconds)

    require IEx; IEx.pry

    if diff < @expiring_soon_in_seconds do
      refresh_now(team)

  alias EspiDni.GoogleAnalyticsClient
  alias EspiDni.Team
  alias EspiDni.Repo

  @expiring_soon_in_seconds 60
  @refresh_wait_in_seconds 2_700
