Quantcast
Channel: Active questions tagged redis+ruby-on-rails - Stack Overflow
Viewing all articles
Browse latest Browse all 873

NameError: uninitialized constant for sidekiq worker in production but works in development

$
0
0

I'm setting up a background task with sidekiq and redis. Have it working completely fine in development, but when testing on staging site I get:

NameError: uninitialized constant InviteWorker::User

/controllers/users_controller.rb

class UsersController < ApplicationControllerdef invite  params[:user] ? @user = User.where(:referral_code => params[:user])[0] : @user = User.find_by_email(cookies[:h_email])  user_id = @user.id  content = params[:body]  emails = params[:email].split(',')  total_emails = emails.length  user_email = @user.email  referral_code = @user.referral_code  cloudsponge_emails = params[:count_cloudsponge]  tracked_count = false  InviteWorker.perform_async(content, emails, total_emails, user_email, referral_code, cloudsponge_emails, tracked_count, user_id)  redirect_to :backend

/app/workers/invite_worker.rb

class InviteWorkerinclude Sidekiq::Workerdef perform(content, emails, total_emails, user_email, referral_code, cloudsponge_emails, tracked_count, user_id)  user = User.find(user_id)  emails.each_with_index do |email,index|    email = email.gsub(/\s+/, '')    if email.include? '<'      email = email.split('<')[1].split('>')[0]    end    if User.where(:email => email).empty? && EmailInvite.where('created_at >= ?', Time.now.beginning_of_day).where(:email => email).empty? && User.new.verify_email(email)      UserMailer.invite_email(content, email, user_email, referral_code).deliver_now      if index == 0 || tracked_count == false        EmailInvite.create(:user => user, :email => email, :count => total_emails)        tracked_count = true      else        EmailInvite.create(:user => user, :email => email)      end    end  endendend

/config/application.rb

config.autoload_paths += %W(  #{config.root}/app/workers  #{config.root}/lib)config.eager_load_paths += %W(  #{config.root}/app/workers  #{config.root}/lib)

Procfile

web:     bundle exec puma -C ./config/puma.rbworker:  bundle exec sidekiq -e $RACK_ENV -r ./config/sidekiq.rb -c ${SIDEKIQ_CONCURRENCY:-5}

Edit - error message provided:

4 TID-u31nw InviteWorker JID-ea609b6557e45a4d299dcde7 INFO: start 4 TID-u31nw InviteWorker JID-ea609b6557e45a4d299dcde7 INFO: fail: 0.002 sec 4 TID-u31nw WARN: {"context":"Job raised exception","job":{"class":"InviteWorker","args":["Hey, join me and sign up!",["email@umd.edu"],1,"email@gmail.com","68QBZ","0",false,2945],"retry":true,"queue":"default","jid":"ea609b6557e45a4d299dcde7","created_at":1531780015.902798,"enqueued_at":1531780015.9035575},"jobstr":"{\"class\":\"InviteWorker\",\"args\":[\"Hey, join me and sign up!\",[\"email@umd.edu\"],1,\"email@gmail.com\",\"68QBZ\",\"0\",false,2945],\"retry\":true,\"queue\":\"default\",\"jid\":\"ea609b6557e45a4d299dcde7\",\"created_at\":1531780015.902798,\"enqueued_at\":1531780015.9035575}"} 4 TID-u31nw WARN: NameError: uninitialized constant InviteWorker::User 4 TID-u31nw WARN: /app/app/workers/invite_worker.rb:5:in `perform'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:187:in `execute_job'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:169:in `block (2 levels) in process'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:128:in `block in invoke'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/middleware/chain.rb:133:in `invoke'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:168:in `block in process'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:139:in `block (6 levels) in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:98:in `local'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:138:in `block (5 levels) in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq.rb:36:in `block in <module:Sidekiq>'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:134:in `block (4 levels) in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:199:in `stats'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:129:in `block (3 levels) in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/job_logger.rb:8:in `call'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:128:in `block (2 levels) in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/job_retry.rb:73:in `global'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:127:in `block in dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:48:in `with_context'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/logging.rb:42:in `with_job_hash_context'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:126:in `dispatch'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:167:in `process'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:85:in `process_one'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:73:in `run'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:16:in `watchdog'/app/vendor/bundle/ruby/2.3.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:25:in `block in safe_thread'

Viewing all articles
Browse latest Browse all 873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>