class Cloudinary::Migrator

def process_results

def process_results
  while self.results.length > 0
    row = self.results.pop
    result = json_decode(row["result"])
    debug("Done ID=#{row['internal_id']}, result=#{result.inspect}")
    complete.call(row["internal_id"], result) if complete
    if result["error"]
      status = case result["error"]["http_code"]
      when 400, 404 then "fatal" # Problematic request. Not a server problem.

      else "error"
      end
    else
      status = "completed"
    end
    updates = {:status=>status, :result=>row["result"]}
    updates["public_id"] = result["public_id"] if result["public_id"] && !row["public_id"]
    begin
      update_row(row, updates)
    rescue SQLite3::ConstraintException
      updates = {:status=>"error", :result=>{:error=>{:message=>"public_id already exists"}}.to_json}
      update_row(row, updates)
    end
  end
end