Weird issue with Sidekiq calling wrong method.

40 views
Skip to first unread message

Angel Jose

unread,
Jul 10, 2015, 2:51:18 PM7/10/15
to sid...@googlegroups.com
I have two sidekiq workers sending out sms's through Twilio.

class SmsWorker
  include Sidekiq::Worker

  sidekiq_options :rate => {                #sidekiq rate-limiter gem
    :limit => 1,
    :period => 180,
  }

  def perform(user_id)
    Sidekiq.redis do |conn|
    user = User.find(user_id)
   if user.invitation_sms
       user.update_attributes(:invited => true, :sms_invite_date => Date.today)
   end
 end
  end

end

class HatsWorker
  include Sidekiq::Worker

  def perform(user_id)
    Sidekiq.redis do |conn|
    user = User.find(user_id)
      user.know_sms
 end
  end

end

from rails console, I can call user.know_sms and send the correct message. But if I try HatsWorker.perform_async(user.id) then a totally different method is executed (user.need_sms).

I have deleted this worker, renamed it, replaced which folder it's loaded from, etc. etc. etc. Can't seem to crack it. Any help would be appreciated!

Mike Perham

unread,
Jul 10, 2015, 6:12:11 PM7/10/15
to sid...@googlegroups.com
Sounds like you have Spring running and caching your code.

Why do you have `Sidekiq.redis` around all your worker code?

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+u...@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/b8fb81c1-72b6-44bc-a2b9-1bbfe5a577a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

Angel Jose

unread,
Jul 10, 2015, 6:38:00 PM7/10/15
to sid...@googlegroups.com
Thanks for replying. 

So I think at the time, I was trying to follow the 'Using Redis' portion of the wiki, although now that you point it out, I don't think I'd been using it correctly. :|

Re: Spring... what is that? Hadn't read anything about it in the docs?

Thanks again.

Mike Perham

unread,
Jul 10, 2015, 6:41:09 PM7/10/15
to sid...@googlegroups.com
Spring is a Rails app preloader, speeds up running your tests but also causes general mayhem, like you're reporting.


For more options, visit https://groups.google.com/d/optout.

Angel Jose

unread,
Jul 10, 2015, 6:46:33 PM7/10/15
to sid...@googlegroups.com
I'm on Rails 3.2.13, so I'm not sure that spring is a factor then (just checked that it comes preloaded in 4+), but the symptoms sound very similar.

At one point, I did call that method from that worker, so it does sound logical that somehow it's calling from the cache, rather than the actual method. Any other suggestions? Or other files that I can post to give some clues?

Thanks.

--
You received this message because you are subscribed to a topic in the Google Groups "Sidekiq" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sidekiq/HNAFMIKqjQQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sidekiq+u...@googlegroups.com.

To post to this group, send email to sid...@googlegroups.com.

Abhi Rao

unread,
Jul 10, 2015, 6:50:16 PM7/10/15
to sid...@googlegroups.com
Angel,

What environment are you running in? The simplest explanation is that sidekiq IS running the old code. Unless you're running something like spring you will need to restart the sidekiq processes to pick up your code changes. Can you confirm that you've restarted the processes?

Mike Perham

unread,
Jul 10, 2015, 6:51:04 PM7/10/15
to sid...@googlegroups.com
You need to restart Sidekiq every time you make a code change.  Sidekiq does not auto-reload code unlike the web server.


For more options, visit https://groups.google.com/d/optout.

Angel Jose

unread,
Jul 10, 2015, 7:05:24 PM7/10/15
to sid...@googlegroups.com
This makes sense. I'm running in a docker environment, yet I thought when I'm stopping and restarting the containers, that would take care of it?

docker-compose stop
docker-compose up

Thanks.
Reply all
Reply to author
Forward
0 new messages