I have a job create_site_map.rb like below:
class CreateSiteMap
@queue = :create_site_map
def self.perform(slct_common_path, http_host, site_id)
end
end
And a rake file:
require "resque/tasks"
require "resque/scheduler/tasks"
namespace :create_site_map do
desc "Create site map"
task create_site_map: :environment do
Resque.enqueue CreateSiteMap, 0, "a", 1071
end
end
When I run resque in Termial :
Resque.enqueue_to(:high, CreateSiteMap, 0, "abc", 1071)
or:
Resque.enqueue(CreateSiteMap)
it's show error like this: wrong number of arguments (given 0, expected 3)
pls help me
How can I pass arguments in resque?
By looking at the code here
https://github.com/resque/resque/blob/master/lib/resque.rb#L386
It seems like, if you are using enqueue
, you should pass the class name and the parameters
# https://github.com/resque/resque/blob/master/lib/resque.rb#L402
def enqueue(klass, *args)
enqueue_to(queue_from_class(klass), klass, *args)
end
or if you are using enqueue_to
,
# https://github.com/resque/resque/blob/master/lib/resque.rb#L415
def enqueue_to(queue, klass, *args)
So, in your case,
# using enqueue
Resque.enqueue(CreateSiteMap, 0, "abc", 1071)
# using enqueue_to
Resque.enqueue_to('high', CreateSiteMap, 0, "abc", 1071)
NOTE: the queue in enqueue_to is a string