2015-06-21 49 views
0

我正在編寫一個Rails 4.2.0應用程序,我需要提供電子郵件。我曾被建議Que gem來管理後臺工作。我已經完成了所有的安裝和使用列表here使用後臺作業管理器gem執行作業的錯誤稱爲Que

而且我在application.rb已經指定了這些行:

# For https://github.com/chanks/que 
    config.active_record.schema_format = :sql 
    config.active_job.queue_adapter = :que 

我的工作看起來像這樣send_welcome_message.rb

class SendWelcomeEmail < Que::Job 
    # Default settings for this job. These are optional - without them, jobs 
    # will default to priority 100 and run immediately. 
    @priority = 10 
    @run_at = proc { 1.minute.from_now } 

    def run(user_id, options) 

    @user = User.find(user_id) 
    UserMailer.welcome_email(@user).deliver_now 

    # Destroy the job. 
    destroy 
    end 
end 

運行rails s命令我的控制檯中填充這些消息後:

{ 
    "lib":"que", 
    "hostname":"...", 
    "pid":13938, 
    "thread":69925811873800, 
    "event":"job_unavailable" 
} 

當我像我的工作排隊像這在控制器

SendWelcomeEmail.enqueue 20, priority: 100

,並刷新頁面,我收到以下錯誤所有的時間(儘管我可以發送消息是同步的方式,而不使用闕):

{ 
    "lib":"que", 
    "hostname":"...", 
    "pid":13938, 
    "thread":69925811873800, 
    "event":"job_errored", 
    "error":{ 
     "class":"ArgumentError", 
     "message":"wrong number of arguments (1 for 2)" 
    }, 
    "job":{ 
     "queue":"", 
     "priority":100, 
     "run_at":"2015-06-22T01:59:45.187+03:00", 
     "job_id":11, 
     "job_class":"SendWelcomeEmail", 
     "args":[ 
     20 
     ], 
     "error_count":2 
    } 
} 

當我打開rails console在第二個終端,並輸入那裏Que.worker_statesit's written here and should return information about every worker in the system)我得到[]

我認爲我沒有工人產卵。我對嗎?以及如何解決它?

UPDATE

在闕日誌

實測值誤差:8

wrong number of arguments (1 for 2) 
/home/username/train/project/app/jobs/send_welcome_email.rb:8:in `run' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/job.rb:15:in `_run' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/job.rb:99:in `block in work' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/adapters/active_record.rb:5:in `block in checkout' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/adapters/active_record.rb:34:in `checkout_activerecord_adapter' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/adapters/active_record.rb:5:in `checkout' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/job.rb:82:in `work' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/worker.rb:78:in `block in work_loop' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/worker.rb:73:in `loop' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/worker.rb:73:in `work_loop' 
/home/username/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/que-0.10.0/lib/que/worker.rb:17:in `block in initialize' 

線是:

def run(user_id, options) 

SOLUTION

現在我ts'工作。我從application.rb刪除適配器配置和在

SendWelcomeEmail.enqueue 20, priority: 100

地方寫

@user = User.find(20) 
SendWelcomeEmail.enqueue @user.id, :priority => 100 

現在,它的作品。在第二種變體中,有趣的是相同的值被傳遞給函數。仍然錯誤消息說,run只獲得1個參數 - 20

回答

0

que寶石,它看起來像enqueue方法治療priority關鍵字作爲一個特殊情況:https://github.com/chanks/que/blob/master/lib/que/job.rb#L31

所以,你run方法僅通過了第一個參數。 priority關鍵字被que吞噬。

改變你run方法

def run(user_id) 

應該解決您的問題。

+0

我會在家裏試試,然後回到這裏。感謝您的調查。 – zmii