[英]Resque Job can't connect to localhost to POST request
我的Resque Job无法连接到localhost以发出POST请求...
当我尝试UserCreatorJob.perform_now(options)
它运行正常。
当我使用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
如果我使用CURL进行发布,一切都会按预期进行。
我认为resque可能不喜欢发布到本地主机。
尝试将此行添加到您的/ etc / hosts文件中:
127.0.0.1 my.api.dev
然后,在您的代码中,将http:// localhost:3000替换为http://my.api.dev:3000
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.