0

I have a Resque Worker that takes two arguments

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.

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

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~!

PrimeTimeTran
  • 1,807
  • 2
  • 17
  • 29
  • 1
    You don't mention if you're testing this in a spec or testing manually by running the server. Either way, it sounds like the `SendPostWorker` class hasn't been reloaded after you updated it (only one argument is expected), so restart your server or stop spring if it's in testing environment. – Jan Klimo Mar 02 '18 at 06:17
  • You are correct. Restarting the worker was the problem. I thought only changing config files required a restart of server/workers =(! – PrimeTimeTran Mar 02 '18 at 06:52

1 Answers1

0

So I fixed this issue after talking to a co-worker. Posting for future readers.

Restart the resque workers after making changes to them.

PrimeTimeTran
  • 1,807
  • 2
  • 17
  • 29