简体   繁体   中英

Resque Job can't connect to localhost to POST request

My Resque Job can't connect to localhost to POST request...

When I try UserCreatorJob.perform_now(options) it runs ok.

When I use UserCreatorJob.perform_later(options) it goes to the resque queue and than, when performing, it fails with Connection refused - connect(2) for "fe80::1%lo0" port 3000

user_creator_job.rb

class UserCreatorJob < Jobs::ApplicationJob
  queue_as :user

  def perform(*args)
    conn :post, 'api/v1/users', args
  end

  def conn
    Faraday.new(url: 'http://localhost:3000') do |faraday|
      faraday.request :url_encoded             # form-encode POST params
      faraday.response :logger                  # log requests to STDOUT
      faraday.adapter Faraday.default_adapter  # make requests with Net::HTTP
      faraday.token_auth('')
    end
  end
end

If I perform the post with CURL everything goes as expected.

I think resque may not like posting to localhost.

Try adding this line to your /etc/hosts file:

127.0.0.1 my.api.dev

Then, in your code, replace http://localhost:3000 with http://my.api.dev:3000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM