     end
   end
 
+  def refresh_token!(team) do
+    Logger.info "Refreshing token for team: #{team.id}"
+    new_token = GoogleAnalyticsClient.get_new_token(team)
+
+    if new_token do
+      team
+      |> Team.changeset(%{google_token: new_token, google_token_expires_at: new_expires_at(team)})
+      |> Repo.update!
+      |> queue_for_refresh()
+    else
+      Logger.error "Could no refresh token for team: #{team.id}"
+    end
+  end
+
   defp refresh_now(team) do
-    Task.async fn ->
-      __MODULE__.refresh_token!(team)
-    end
+    __MODULE__.refresh_token!(team)
   end
 
   defp refresh_later(team, delay) do
     Logger.info "Queueing token refresh for team: #{team.id} in #{delay}ms"
     :timer.apply_after(delay, __MODULE__, :refresh_token!, [team])
-  end
-
-  def refresh_token!(team) do
-    Logger.info "Refreshing token for team: #{team.id}"
-    new_token =  EspiDni.GoogleAnalyticsClient.get_new_token(team)
-
-    if new_token do
-      team
-      |> Team.changeset(%{google_token: new_token, google_token_expires_at: new_expires_at(team)})
-      |> Repo.update()
-      |> elem(1)
-      |> queue_for_refresh()
-    else
-      Logger.error "Could no refresh token for team: #{team.id}"
-    end
   end
 
   defp expires_in_unix(team) do

  alias EspiDni.GoogleAnalyticsClient
  alias EspiDni.Team
  alias EspiDni.Repo
  import Ecto.Query, only: [from: 1, from: 2]

  @expiring_soon_in_seconds 60
  @refresh_wait_in_seconds 2_700

  end

  def queue_for_refresh(team) do
    diff = expires_in_unix(team) - :os.system_time(:seconds)

    if diff < @expiring_soon_in_seconds do
      refresh_now(team)
