简体   繁体   English

将多个参数传递给Resque和Resque-Scheduler

[英]Pass Multiple Arguments to Resque & Resque-Scheduler

I have a Resque Worker that takes two arguments 我有一个Resque Worker,需要两个论点

class SendPostWorker
  @queue = :send_post_worker

  def self.perform(post_id, group_id)
    group = Group.find(group_id.to_i)
    ::BotMessageDispatcher.new(group, post_id).work
  end
end

In a controller action, I use Resque & Resque-scheduler to enqueue the job. 在控制器操作中,我使用Resque&Resque-scheduler来排队工作。

class PostsController < ApplicationController
  def create
    # Code
    Resque.enqueue_in(@post.scheduled_time - Time.now, SendPostWorker, @post.id, params['groups']['group'].to_i)
    # Code
  end
end

The worker initially worked fine when I hardcoded the params['groups']['group'] argument within the worker(passed only one argument to it), but now that I try to make the job smarter(receiving group id from the controller), it complains about number of arguments being passed 当我在工作程序中将params ['groups'] ['group']参数硬编码(仅传递一个参数)时,工作程序最初工作正常,但是现在我尝试使工作更智能(从控制器接收组ID) ),它抱怨传递了数量的参数

ArgumentError Error wrong number of arguments (given 2, expected 1) /Users/Lois/Desktop/projects/bot/app/workers/send_post_worker.rb:4:in `perform'

Thanks for your help in advance~! 谢谢您的帮助〜!

So I fixed this issue after talking to a co-worker. 因此,在与同事交谈后,我解决了此问题。 Posting for future readers. 发布给将来的读者。

Restart the resque workers after making changes to them. 对其进行更改后,请重新启动重新启动的工作程序。

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

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