2013-03-13 1 views
2

sidekiq 작업자 클래스가 있습니다. 나는 현재이 방법으로 구현했다. 그것은 PROCESS를 호출 할 때 작동하며 PERFORM이라는 메소드를 대기열에 넣습니다. 하지만 대기열에 넣을 수있는 방법이 두 가지 이상 있습니다.sidekiq 작업자 클래스에 둘 이상의 메서드가있는 경우

부수적으로이 작업을 수행하는 데 차이가 있으며 단순히 SocialSharer.delay.perform을 수행하고 있습니까?

# I trigger by using SocialSharer.process("xxx") 

class SocialSharer 

    include Sidekiq::Worker 

    def perform(user_id) 
    # does things 
    end 

    def perform_other_things 
    #i do not know how to trigger this 
    end 

    class << self 
    def process(user_id) 
     Sidekiq::Client.enqueue(SocialSharer,user_id) 
    end 
    end 

end 

답변

5

SocialSharer.delay.perform은 perform이라는 클래스 메소드를 지연시킵니다. perform 메소드는 인스턴스 메소드입니다.

작업자는 작업마다 하나의 클래스로 설계되었습니다. 작업은 perform 메소드를 통해 시작됩니다. 당신은 너무 같은 클래스에서 다른 클래스 메소드의 수를 킥오프 지연을 사용할 수 있습니다 : 당신이 정말는 하나 개의 클래스에있는 모든 "수행 될 수있는"방법을 갖고 싶어

class Foo 
    def self.a(count) 
    end 
    def self.b(name) 
    end 
end 
Foo.delay.a(10) 
Foo.delay.b('bob') 
+0

나는 아직도 내가 전화하는 방법 내부에서 레일 환경에 액세스 할 수 있습니까를 지연? – holaSenor

+0

이것은 지연된 작업으로 수행 할 수 있으며, Sidekiq을 사용하여 동일한 작업을 수행하는 방법은 무엇입니까? –

-3
에게

글쎄, 내가 좋을 것 당신은 뭔가 다른 (예를 들어, perform_something)에 perform 방법의 이름을 변경하고, 제어 흐름 파견하는 새로운 perform 방법을 만들 수 있습니다 :

class SocialSharer 
    include Sidekiq::Worker 

    # the 3 lines below may be replaced with `alias_method :perform, :public_send` 
    def perform(method, *args) 
    self.public_send(method, *args) 
    end 

    def perform_something(user_id) 
    # does things 
    end 

    def perform_other_things 
    # does other things 
    end 

    def self.process(user_id) 
    Sidekiq::Client.enqueue(SocialSharer, :perform_something, user_id) 
    Sidekiq::Client.enqueue(SocialSharer, :perform_other_things) 
    end 
end 
+1

아아, 그건 사이드 키크 노동자들이 일하는 방식이 아니야. –

관련 문제