collectiveidea/delayed_job_active_record

Urgent - undefined method `wicked_pdf_stylesheet_link_tag' for #<ActionView::Base:0x00000009d11858>

vishaltps opened this issue · 10 comments

Its very weird type of issue . and not its become headache for me .

i am generating PDF with wicked pdf . i used delayed job for generating PDF
in background

I used AWS Classic load balancer for my application. earlier everything was working fine but from last 30 days whenever new instance generate i need to restart the delayed job for successful generation of PDF.
if i don't restart the delayed job than i get below error .

undefined method wicked_pdf_stylesheet_link_tag' for #<ActionView::Base:0x00000009d11858>\n/var/www/project/lessons-matchmaker/app/views/instructor/home/group_classes_pdf.html.erb:2:in _app_views_instructor_home_group_classes_pdf_html_erb___1024770791689151783_83694240'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/template.rb:145:in block in render'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications.rb:161:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/template.rb:339:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/template.rb:143:in render'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:55:in block (2 levels) in render_template'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/abstract_renderer.rb:38:in block in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in block in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/abstract_renderer.rb:38:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:54:in block in render_template'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:62:in render_with_layout'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:53:in render_template'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/template_renderer.rb:17:in render'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:42:in render_template'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/renderer/renderer.rb:23:in render'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/helpers/rendering_helper.rb:32:in render'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/haml-4.1.0.beta.1/lib/haml/helpers/action_view_mods.rb:12:in render_with_haml'\n/var/www/project/lessons-matchmaker/app/services/pdf_generator.rb:36:in call'\n/var/www/project/lessons-matchmaker/app/mailers/classes_pdf_mailer.rb:5:in send_classes_details'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:189:in process_action'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:20:in block in process_action'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:82:in run_callbacks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionpack-4.1.1/lib/abstract_controller/callbacks.rb:19:in process_action'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionpack-4.1.1/lib/abstract_controller/base.rb:136:in process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionview-4.1.1/lib/action_view/rendering.rb:30:in process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionmailer-4.1.1/lib/action_mailer/base.rb:580:in block in process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in block in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in instrument'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionmailer-4.1.1/lib/action_mailer/base.rb:577:in process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionmailer-4.1.1/lib/action_mailer/base.rb:568:in initialize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionmailer-4.1.1/lib/action_mailer/base.rb:551:in new'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/actionmailer-4.1.1/lib/action_mailer/base.rb:551:in method_missing'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/performable_mailer.rb:6:in perform'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:94:in block in invoke_job'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in block in initialize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in execute'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in run_callbacks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:91:in invoke_job'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:204:in block (2 levels) in run'\n/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:91:in block in timeout'\n/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in call'\n/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in timeout'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:204:in block in run'\n/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in realtime'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:203:in run'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in block in reserve_and_run_one_job'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in block in initialize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in execute'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in run_callbacks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in reserve_and_run_one_job'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:187:in block in work_off'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in times'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in work_off'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:150:in block (4 levels) in start'\n/usr/local/rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in realtime'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:149:in block (3 levels) in start'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in block in initialize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in execute'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in run_callbacks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:148:in block (2 levels) in start'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in loop'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in block in start'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/plugins/clear_locks.rb:7:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/plugins/clear_locks.rb:7:in block (2 levels) in class:ClearLocks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in block (2 levels) in add'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in block in initialize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in block in add'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in execute'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in run_callbacks'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/worker.rb:146:in start'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:124:in run'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:112:in block in run_process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/application.rb:255:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/application.rb:255:in block in start_proc'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in call_as_daemon'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/application.rb:259:in start_proc'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/application.rb:296:in start'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/controller.rb:70:in run'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons.rb:197:in block in run_proc'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in call'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in catch_exceptions'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/daemons-1.1.9/lib/daemons.rb:196:in run_proc'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:110:in run_process'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:91:in block in daemonize'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:89:in times'\n/usr/local/rvm/gems/ruby-2.1.2@ssa/gems/delayed_job-4.0.6/lib/delayed/command.rb:89:in daemonize'\nbin/delayed_job:5:in

'
once if i restart the delay job in new instance everything works fine.
i am sure this issue is from delayed job.
Please help me to resolve this issue ASAP

That error is nothing DJ is doing. The error is essentially telling you that Wicked PDF is not loaded as Wicked PDF injects those methods into ActionView::Base on app initialization. The most common cause of the issue you are seeing is a worker somewhere running and old version of your code that you thought had quit but didn't. Another scenario is that your manual restart is executing differently than your on system startup script is. Possible issues there are things like environment variables or working directory. Also certain startup utilities can cause your process to fixate on an old Gemfile and not pickup new gemfiles on restart, an example of this would be god (https://rubygems.org/gems/god).

@albus522 Thanks for your reply, how can i know a worker somewhere running and old version of my code ? because there are no any pending jobs in database. the other scenario manual restart is not different, because earlier the everything was working fine. does environment variables create issue ? because currently i am generating file .env.production from user_script whenever new instance generate that time it will generate this file and set environment variables. but i also change script and remove environment variables's file creation from script. but still same issue .

The easiest way to confirm all workers are running the latest code is to fully stop all delayed job workers and use what ever your systems process listing utility is to make sure all processes have stopped and then startup fresh.

As for environment variables, there are many things happening there. For instance, starting a process from an @reboot in the crontab is a very different environment than running on a bash command line. Things can get even weirder on the command line if you are changing users to run processes. Also certain libraries, like bundler, add a bunch of environments to the running process on startup. One of those variables is the file path to the gemfile. Depending on your environment, this can cause bundler to fixate on a release path gemfile instead of a current release path.

@albus522 Please see below user script, it will run whenever new instance create
#!/bin/bash


echo "Begin of deploy script ----- $(date)" | tee -a /tmp/deploy.txt

. ~/.bash_profile
cd /var/www/project/lessons-matchmaker/ 

echo "Updating source code ..." | tee -a /tmp/deploy.txt
git pull new_repo ssa_master  | tee -a /tmp/deploy.txt

echo "Running bundle install..." | tee -a /tmp/deploy.txt
bundle install | tee -a /tmp/deploy.txt

echo "Running rake... " | tee -a /tmp/deploy.txt
RAILS_ENV=production rake db:migrate  | tee -a /tmp/deploy.txt

echo "Generating env production file..." | tee -a /tmp/deploy.txt

echo "Starting node js server with forever..." | tee -a /tmp/deploy.txt
forever start socket/socket-server.js

touch .env.production

echo "AWS_S3_REGION='*************************'
AWS_ACCESS_KEY_ID='***********************'
AWS_SECRET_ACCESS_KEY='********************'
AWS_S3_BUCKET_PROD='*******************'
AWS_S3_HOST_NAME='*************************'" > .env.production

touch tmp/restart.txt


sleep 300
echo "Running delay job..." | tee -a /tmp/deploy.txt
RAILS_ENV=production bin/delayed_job restart

echo "End deploy script ----- $(date)" | tee -a /tmp/deploy.txt

This is my user script as per your response, i think first of all i need to stop the delayed job with RAILS_ENV=production bin/delayed_job stop than again start the delayed job with this command RAILS_ENV=production bin/delayed_job start. is it correct ?

Do the stop and start to manually confirm there aren't any orphaned processes. The restart command generally runs fine, but it is known to hiccup on occasion. The daemons gem we rely on generally does a great job, but every once in a while something strange will happen that causes things to get into weird states.

@albus522 manually start and stop working fine. should try it in user scripts ?

Shouldn't be necessary, but you could try.

@albus522 i don't have any option how to fix this issue.. :(

All I can do is point you at things that might be causing the symptoms you are reporting, but it isn't actually a problem with DJ. DJ is simply initializing your app the same way a console session or server does and then running a loop in that environment that finds and executes each job. There really isn't anything magical about what DJ does.

@albus522 Changed the script but same issue again