简体   繁体   English

Resque Job无法连接到本地主机以进行POST请求

[英]Resque Job can't connect to localhost to POST request

My Resque Job can't connect to localhost to POST request... 我的Resque Job无法连接到localhost以发出POST请求...

When I try UserCreatorJob.perform_now(options) it runs ok. 当我尝试UserCreatorJob.perform_now(options)它运行正常。

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 当我使用UserCreatorJob.perform_later(options)它进入resque队列,然后在执行时失败, 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. 如果我使用CURL进行发布,一切都会按预期进行。

I think resque may not like posting to localhost. 我认为resque可能不喜欢发布到本地主机。

Try adding this line to your /etc/hosts file: 尝试将此行添加到您的/ etc / hosts文件中:

127.0.0.1 my.api.dev

Then, in your code, replace http://localhost:3000 with http://my.api.dev:3000 然后,在您的代码中,将http:// localhost:3000替换为http://my.api.dev:3000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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