           changeset = CollectorLog.changeset(collector_log, %{done: true})
           {:ok, collector_log} = Repo.update(changeset)
         else
+          changeset = CollectorLog.changeset(collector_log, %{
+            fetch_count: collector_log.fetch_count + 1,
+            message_count: collector_log.message_count + length(comments),
+            next_url: body.paging.next
+          })
+
+          # TODO(yu): This should be inside the transaction but it raises an
+          # error for some reason
+          {:ok, collector_log} = Repo.update(changeset)
           Repo.transaction fn ->
-            changeset = CollectorLog.changeset(collector_log, %{
-              fetch_count: collector_log.fetch_count + 1,
-              message_count: collector_log.message_count + length(comments),
-              next_url: body.paging.next
-            })
-            {:ok, collector_log} = Repo.update(changeset)
-
             process_comments(comments, collector_log)
           end
-
-          IO.puts "#{collector_log.fetch_count} - total: #{collector_log.message_count}, add #{length(comments)} comments, first: #{List.first(comments).created_time}"
         end
 
-       :timer.sleep(1500)
-        fetch_next(collector_log)
+        IO.puts """
+        #{collector_log.fetch_count} -
+        total: #{collector_log.message_count},
+        add #{length(comments)} comments, first:
+        #{List.first(comments).created_time}
+        """
+
+        :timer.sleep(1500)
+        fetch_next(collector_log, tracer ++ [collector_log.fetch_count])
+      true ->
+        IO.puts """
+        done fetching #{collector_log.message_count} messages
+        in #{collector_log.fetch_count} fetches
+        """
+
+        {:ok, collector_log}
     end
   end
 

  alias Betazoids.Facebook
  alias Betazoids.Repo


  def start_link do
    Supervisor.start_link(__MODULE__, [], [name: Betazoids.Collector])

        message_count: length(res.comments),
        next_url: res.paging.next
      })
      {:ok, updated_collector_log} = Repo.update(changeset)

      process_comments(res.comments, updated_collector_log)
      updated_collector_log
    end
  end

  defp fetch_next(collector_log, tracer \\ []) do
    IO.puts "********************************************"
    IO.puts "tracer #{inspect tracer}"
    IO.puts "********************************************"
    case collector_log.done do
      false ->
        next_path = path_from_url(collector_log.next_url)
        %HTTPoison.Response{status_code: 200, body: body} = Facebook.get!(next_path)
