   end
 
   defp maybe_start_next_attempt(_state, project) do
-    case Repo.one(Attempt.all_for_project(project.id, :waiting)) do
-      nil -> :ok
-      attempt ->
+    case Repo.all(Attempt.all_for_project(project.id, :waiting)) do
+      [] -> :ok
+      [attempt | _] ->
         maybe_start_attempt(attempt, project)
     end
   end

  def do_handle_cast({:cancel, patch_id}, project_id) do
    patch = Repo.get!(Patch, patch_id)
    ^project_id = patch.project_id
    case Repo.one(Attempt.all_for_patch(patch_id, :incomplete)) do
      nil ->
        :ok
      attempt ->
        attempt
        |> Attempt.changeset_state(%{state: :canceled})
        |> Repo.update!()

          |> Repo.insert!()
          |> maybe_start_attempt(project)
        end
      [_attempt | _] ->
        # There is already a running attempt
        project
        |> get_repo_conn()
