0

내 Rails 앱에서 Resque로 작동하도록 ActiveJob 설정이 있습니다.Resque 작업이 외부 호스트에 연결할 수 없습니다.

class SendPushNotificationJob < ActiveJob::Base 
    queue_as :default 

    def perform(device_token, msg) 
    # TODO: Move the grocer initialization somewhere else. 
    pusher = Grocer.pusher(
     certificate: ENV['PUSH_CERT_PATH'], 
     passphrase: ENV['PUSH_CERT_KEY'], 
     gateway:  "gateway.sandbox.push.apple.com", 
     port:  2195, 
     retries:  3 
    ) 

    Resque.logger.debug "PUSHER OBJECT IS #{pusher.inspect}!" 

    notification = Grocer::Notification.new(
    device_token: device_token, 
    alert: msg) 

    Resque.logger.debug "NOTIFICATION OBJECT IS #{notification.inspect}" 

    res = pusher.push(notification) 

    Resque.logger.debug "PUSH RESULT IS #{res.inspect}" 
    end 
end 

이 작업이 포착된다 Resque 로그의 출력은 다음과 같습니다 :

** [22:08:31 2016-07-06] 24074: Found job on default 
** [22:08:31 2016-07-06] 24074: got: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"SendPushNotificationJob", "job_id"=>"c88619a4-d2ea-4b27-a3c8-3ea5be04a130", "queue_name"=>"default", "arguments"=>["<my_device_token>", "Test message"], "locale"=>"en"}]) 
** [22:08:31 2016-07-06] 24074: resque-1.26.0: Processing default since 1467860911 [ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper] 
** [22:08:31 2016-07-06] 24074: Running before_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"SendPushNotificationJob", "job_id"=>"c88619a4-d2ea-4b27-a3c8-3ea5be04a130", "queue_name"=>"default", "arguments"=>["<my_device_token>", "Test message"], "locale"=>"en"}])] 
** [22:08:31 2016-07-06] 24074: resque-1.26.0: Forked 24092 at 1467860911 
** [22:08:31 2016-07-06] 24092: Running after_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"SendPushNotificationJob", "job_id"=>"c88619a4-d2ea-4b27-a3c8-3ea5be04a130", "queue_name"=>"default", "arguments"=>["<my_device_token>", "Test message"], "locale"=>"en"}])] 
** [22:08:31 2016-07-06] 24092: PUSHER OBJECT IS #<Grocer::Pusher:0x007f862152f4f0 @connection=#<Grocer::Connection:0x007f862152f630 @certificate="<cert path>", @passphrase="<passphrase>", @gateway="gateway.sandbox.push.apple.com", @port=2195, @retries=3>>! 
** [22:08:31 2016-07-06] 24092: NOTIFICATION OBJECT IS #<Grocer::Notification:0x007f8627a23f00 @identifier=0, @device_token="<my_device_token>", @alert="Test message", @encoded_payload=nil> 

다음 예외가 발생하는 나는 아이폰 OS가 grocer 보석과 푸시 알림을 보낼 수있는이 일을 만들었습니다 : 여기

** [22:08:31 2016-07-06] 24092: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"SendPushNotificationJob", "job_id"=>"c88619a4-d2ea-4b27-a3c8-3ea5be04a130", "queue_name"=>"default", "arguments"=>["<my_device_token>", "Test message"], "locale"=>"en"}]) failed: #<SocketError: getaddrinfo: nodename nor servname provided, or not known> 

내가 무엇을 알고 :

  1. 게이트웨이 URL을 올바르게 설정하고 있습니다.
  2. 환경 변수가 올바르게 설정되었습니다.
  3. 이 작업은 perform_later 대신 perform_now을 사용할 때 작동합니다.

는 마지막으로,이 grocer에 문제가되지 않습니다. 박사, 없음,

** [22:14:41 2016-07-06] 24285: Found job on default 
** [22:14:41 2016-07-06] 24285: got: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"TestExternalConnectionJob", "job_id"=>"523da5ca-2b6c-452e-95ef-33edece69996", "queue_name"=>"default", "arguments"=>["http://stackoverflow.com"], "locale"=>"en"}]) 
** [22:14:41 2016-07-06] 24285: resque-1.26.0: Processing default since 1467861281 [ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper] 
** [22:14:41 2016-07-06] 24285: Running before_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"TestExternalConnectionJob", "job_id"=>"523da5ca-2b6c-452e-95ef-33edece69996", "queue_name"=>"default", "arguments"=>["http://stackoverflow.com"], "locale"=>"en"}])] 
** [22:14:41 2016-07-06] 24285: resque-1.26.0: Forked 24300 at 1467861281 
** [22:14:41 2016-07-06] 24300: Running after_fork hooks with [(Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"TestExternalConnectionJob", "job_id"=>"523da5ca-2b6c-452e-95ef-33edece69996", "queue_name"=>"default", "arguments"=>["http://stackoverflow.com"], "locale"=>"en"}])] 
** [22:14:41 2016-07-06] 24300: (Job{default} | ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper | [{"job_class"=>"TestExternalConnectionJob", "job_id"=>"523da5ca-2b6c-452e-95ef-33edece69996", "queue_name"=>"default", "arguments"=>["http://stackoverflow.com"], "locale"=>"en"}]) failed: #<SocketError: Failed to open TCP connection to stackoverflow.com:80 (getaddrinfo: nodename nor servname provided, or not known)> 

그래서, TL : 레일 콘솔에서 TestExternalConnectionJob.perform_later('http://stackoverflow.com') 실행

class TestExternalConnectionJob < ActiveJob::Base 
    queue_as :default 

    def perform(url) 
    res = HTTParty.get(url) 

    if res 
     Resque.logger.debug "SUCCESS" 
     Resque.logger.debug res.body 
    else 
     Resque.logger.debug "FAILURE"  
    end 
    end 
end 

가 Resque 로그에이 출력을 생성 : 나는 단순히 URL의 소스를 기록 다른 작업을 만든 내 Resque 작업은 외부 서비스에 연결할 수 있습니다.

부록

lib/resque.rake 파일 :

require 'resque/tasks' 

namespace :resque do 
    task :setup => :environment do 
    require 'resque' 
    end 
end 

config/initializers/resque.rb 파일 :

require 'resque' 

Resque.redis = Redis.new(url: 'redis://127.0.0.1:6379') 
Resque.logger = Logger.new(Rails.root.join('log', "#{Rails.env}_resque.log")) 
Resque.logger.level = Logger::DEBUG 
Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection } 

답변

2

글쎄, 그 질문을 작성하는 시간의 엄청난 낭비이다.

재부팅 후 모든 프로세스를 다시 시작한 후 외부 호스트에 연결할 수있었습니다.

이전에는 번을없이 다시 시작했습니다. 나는 그들을 처리하기 위해 eye을 사용하고 있으므로이 문제를 해결하기 위해 여러 번 시도했다. eye restart 명령을 내 애플 리케이션이 (postgres, redisresque-worker)에 의존하는 모든 프로세스를 다시 시작했다. 다시 시작할 때마다 동일한 오류가 발생합니다.

하지만 어떻게 든 재부팅이 트릭을했습니다.

컴퓨터가 때때로 이상합니다.

관련 문제