0

I wrote a rake task that populates my database with data from a third-party API.

namespace :populate do
desc "Populate database with data from first page of TicketWeb API"
task :one_page => :environment do
    require 'open-uri'
    json_data = open(SOME_URL).read
    parsed_json = JSON.parse(json_data)
    parsed_json["events"].each do |e|
        existing_event = Event.find_by_id(e["eventid"])
        if existing_event == nil
            new_event = Event.new(e)
            new_event.save
        else
            existing_event.update_attributes(e)
        end
    end
end

end

This works perfectly when running locally on my machine. However, running it on a Heroku instance results in this error:

rake aborted! Connection refused - connect(2)

I will admit I'm not very experienced with Rails, so I'm not sure if I'm fetching the data from the third-party API in a correct way or if Heroku just doesn't like what I'm doing. I am just stumped, at the moment.

Pance
  • 101
  • 2

1 Answers1

0

Turns out the third-party API was blocking any requests coming from Heroku.

I got around this by pushing my local database to Heroku's database with this command:

heroku db:push
Pance
  • 101
  • 2