ruby on rails - Stop sidekiq worker when user logs out -
i want perform background job when user logged in. when user logged in, start worker:
warden::manager.after_authentication |user,auth,opts| imapworker.perform_async(user.id) end
all imapworker use ruby's net::imap
api wait new emails come in remote email server. uses imap's idle functionality wait new events.
class imapworker include sidekiq::worker def perform(user_id) user = user.find(user_id) imap = net::imap.new('imap.gmail.com',993,true) imap.login(user.email, user.password) imap.select('inbox') imap.add_response_handler |resp| if resp.kind_of?(net::imap::untaggedresponse) , resp.name == "exists" check_email end end imap.idle end end
now when user logs out, want end worker. know in devise
, can hook log out functionality such:
warden::manager.before_logout |user,auth,opts| ... end
but how stop sidekiq worker?
require 'sidekiq/api'; sidekiq::processset.new.each(&:stop!)
Comments
Post a Comment