Hide arguments while logging to delayed_job.log for ActionMailer::MailDeliveryJob / ActionJob / DelayedJob - delayed-job

Similar to disable-logging-arguments I would like to stop rails to log arguments when sending emails via ActionMailer.
We used to deliver emails to users with a Notifier like Notifier.delay.forgot_password(user_id) using delayed_job. Logging was done to log/delayed_job.log:
I, [...] INFO -- : 2022-08-08T17:33:30+0200: [Worker(delayed_job host:noname pid:23456)] Job Notifier.forgot_password (id=1234) RUNNING
I, [...] INFO -- : 2022-08-08T17:33:30+0200: [Worker(delayed_job host:noname pid:23456)] Job Notifier.forgot_password (id=1234) COMPLETED after 0.0636
I, [...] INFO -- : 2022-08-08T17:33:30+0200: [Worker(delayed_job host:noname pid:23456)] 1 jobs processed at 14.1552 j/s, 0 failed
Now we changed to use ActiveJob an intermediary and use Notifier.forgot_password(user_id).deliver_later. Now, performing the same tasks the log gets cluttered with sensitive information:
I, [...] INFO -- : 2022-08-08T19:31:48+0200: [Worker(delayed_job host:noname pid:423423)] Job ActionMailer::MailDeliveryJob [...] from DelayedJob(production_mailers) with arguments: ["Notifier", "forgot_password", "deliver_now", {"args"=>[123, "UnencryptedPassword"], "_aj_ruby2_keywords"=>["args"]}] (id=27225) (queue=production_mailers) RUNNING
I, [...] INFO -- : 2022-08-08T19:31:48+0200: [Worker(delayed_job host:noname pid:423423)] Job ActionMailer::MailDeliveryJob [...] from DelayedJob(production_mailers) with arguments: ["Notifier", "forgot_password", "deliver_now", {"args"=>[123, "UnencryptedPassword"], "_aj_ruby2_keywords"=>["args"]}] (id=27225) (queue=production_mailers) COMPLETED after 0.0994
I, [...] INFO -- : 2022-08-08T19:31:48+0200: [Worker(delayed_job host:noname pid:423423)] 1 jobs processed at 8.6654 j/s, 0 failed
I tried the solution with self.log_arguments = false in different places, also NoArgumentsLoggingMailDeliveryJob as suggested in the linked answer. Nothing changes. Why doesn't it have any effect?
I am using Ruby 2.7.6 and Rails 6.1.6.1.
Environment is production.
delayed_job is 4.1.10

Related

Remove delay for some emails using SideKiq

I'm using SideKiq and Redis to deliver emails asynchronously on my Rails (4.2) site but some emails take too long to send. Most emails take between 5 and 15 minutes to to be delivered (I'm not sure if this is normal and may be part of the problem). For most emails I send this wait is fine, but for confirmation emails, I need them to be sent more or less immediately.
Normally when I send an email, I send it like this:
UserMailer.delay.my_email(args)
To send an email immediately, I have tried all of the following:
UserMailer.my_email(args).deliver
UserMailer.my_email(args).deliver!
UserMailer.my_email(args).deliver_now
UserMailer.my_email(args).deliver_now!
However all of these result in a 504 error. When I try to send an email, the page waits for several seconds and then I get in my unicorn.log is:
Started POST "/my-path/" for 0.0.0.0 at 0000-00-00 00:00:00 +0000
Processing by MyController#my_path as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", ...}
Rendered user_mailer/my_email.html.haml within layouts/user_mailer (0.0ms)
E, [0000-00-00T00:00:00.000000 #00000] ERROR -- : worker=1 PID:00000 timeout (61s > 60s), killing
E, [0000-00-00T00:00:00.000000 #00000] ERROR -- : reaped #<Process::Status: pid 00000 SIGKILL (signal 9)> worker=1
I, [0000-00-00T00:00:00.000000 #00000] INFO -- : worker=1 spawning...
I, [0000-00-00T00:00:00.000000 #00001] INFO -- : worker=1 spawned pid=00001
I, [0000-00-00T00:00:00.000000 #00001] INFO -- : Refreshing Gem list
I, [0000-00-00T00:00:00.000000 #00001] INFO -- : worker=1 ready
This is my sidekiq.yml (the both production and preview are taking a very long time):
---
:concurrency: 5
:logfile: log/sidekiq.log
preview:
:pidfile: /home/unicorn/sidekiq_preview.pid
production:
:pidfile: /home/unicorn/sidekiq_production.pid
:concurrency: 15
I'm not getting anything in my sidekiq.log or mail.log.

Rails Delayed job: job is not running from the table

I am starting delayed job with command RAILS_ENV=production bin/delayed_job -n 5 start.delayed job is performing heavy database operation and each delayed job process is taking almost 15 minutes to complete.
For testing purpose i ran 3 jobs simultaneously of of which two jobs processed successfully and remaining 1 job is not processing. This job is in the delayed job table but still it is not running.
***********************delayed job log********************************
er(delayed_job.4 host:ip-172-31-6-58 pid:1524)] Starting job worker
I, [2015-12-15T05:36:26.154690 #1498] INFO -- : 2015-12-15T05:36:26+0000: [Worker(delayed_job.0 host:ip-172-31-6-58 pid:1498)] Job QrCodeGenerator (id=1) RUNNING
I, [2015-12-15T05:36:26.229763 #1504] INFO -- : 2015-12-15T05:36:26+0000: [Worker(delayed_job.1 host:ip-172-31-6-58 pid:1504)] Job QrCodeGenerator (id=2) RUNNING
I, [2015-12-15T05:36:41.322419 #1510] INFO -- : 2015-12-15T05:36:41+0000: [Worker(delayed_job.2 host:ip-172-31-6-58 pid:1510)] Job QrCodeGenerator (id=3) RUNNING
I, [2015-12-15T05:50:51.485299 #1510] INFO -- : 2015-12-15T05:50:51+0000: [Worker(delayed_job.2 host:ip-172-31-6-58 pid:1510)] Job QrCodeGenerator (id=3) COMPLETED after 850.1627
I, [2015-12-15T05:50:51.488960 #1510] INFO -- : 2015-12-15T05:50:51+0000: [Worker(delayed_job.2 host:ip-172-31-6-58 pid:1510)] 1 jobs processed at 0.0012 j/s, 0 failed
I, [2015-12-15T05:50:59.107773 #1498] INFO -- : 2015-12-15T05:50:59+0000: [Worker(delayed_job.0 host:ip-172-31-6-58 pid:1498)] Job QrCodeGenerator (id=1) COMPLETED after 872.9529
I, [2015-12-15T05:50:59.108821 #1498] INFO -- : 2015-12-15T05:50:59+0000: [Worker(delayed_job.0 host:ip-172-31-6-58 pid:1498)] 1 jobs processed at 0.0011 j/s, 0 failed
*********************remaining entry with Delayed::Job.all*************
2.0.0-p598 :001 > Delayed::Job.all
=> #<ActiveRecord::Relation [#<Delayed::Backend::ActiveRecord::Job id: 2, priority: 0, attempts: 0, handler: "--- !ruby/struct:QrCodeGenerator\nclient: !ruby/obj...", last_error: nil, run_at: "2015-12-15 08:17:22", locked_at: "2015-12-15 05:36:26", failed_at: nil, locked_by: "delayed_job.1 host:ip-172-31-6-58 pid:1504", queue: nil, created_at: "2015-12-15 05:36:23", updated_at: "2015-12-15 08:17:26">]>
Please help.
Thanks,

Unicorn workers timeout

I'm developing an AngularJS (front-end) running in an Nginx web server that sends request to a Rails API (backend) running in a Unicorn application server.
I recognize I'm just a developer and I have no idea about servers administration, so I just put the servers and start them.
The application is working, however, Unicorn has a strange behaviour. When I start it I always get this error:
roberto#ubuntu:~/dev/scripts$ ./start_unicorn.sh
I, [2014-06-14T11:46:06.085834 #4258] INFO -- : Refreshing Gem list
I, [2014-06-14T11:46:11.591592 #4258] INFO -- : listening on addr=0.0.0.0:8080 fd=10
I, [2014-06-14T11:46:12.087321 #4258] INFO -- : master process ready
I, [2014-06-14T11:46:12.151320 #4263] INFO -- : worker=0 ready
I, [2014-06-14T11:46:12.150526 #4266] INFO -- : worker=1 ready
E, [2014-06-14T11:46:39.112668 #4258] ERROR -- : worker=0 PID:4263 timeout (16s > 15s), killing
E, [2014-06-14T11:46:39.112898 #4258] ERROR -- : worker=1 PID:4266 timeout (16s > 15s), killing
E, [2014-06-14T11:46:39.118081 #4258] ERROR -- : reaped #<Process::Status: pid 4263 SIGKILL (signal 9)> worker=0
E, [2014-06-14T11:46:39.118634 #4258] ERROR -- : worker=1 PID:4266 timeout (16s > 15s), killing
E, [2014-06-14T11:46:39.121820 #4258] ERROR -- : reaped #<Process::Status: pid 4266 SIGKILL (signal 9)> worker=1
I, [2014-06-14T11:46:39.172067 #4284] INFO -- : worker=1 ready
I, [2014-06-14T11:46:39.172620 #4281] INFO -- : worker=0 ready
It takes some seconds until it responds. And this happens continuosly.
I guess I'm missing some configuration but no idea...
If you need any more details, such as config files, just let me know
Do you have your assets precompiled ? are you in production ?
If not when you start your server and get your first request, rails will try to compile your assets which can take more than 15 seconds and reach the unicorn timeout.
In your start.sh you should have somewhere
export RAILS_ENVIRONEMENT=production
And during you deployment you should have :
rake assets:precompile

Rails 3.2, Ruby 1.9 and Unicorn - The First Request is Very Slow - How to debug?

I've got a large 2.3 Rails app running on Unicorn. I'm using Unicorn, so that I can have zero downtime deployments. However, I've noticed that the first request after a restart is very slow.
First request:
Completed 304 Not Modified in 2771.8ms (ActiveRecord: 98.6ms)
Second request:
Completed 304 Not Modified in 94.4ms (ActiveRecord: 26.9ms)
I do have preload_app true and I am re-establishing the db-connection in the after-fork.
I have no idea how to explain the 2600ms divergence between these two values.
Does anyone have any thoughts? Really, what I am looking for are ways to debug this issue.
UPDATE
Here is my unicorn.log after a restart:
I, [2014-05-16T13:46:26.529305 #11637] INFO -- : executing ["/data/app/current/ey_bundler_binstubs/unicorn", "-E", "staging", "-c", "/data/app/shared/config/custom_unicorn.rb", "-D", "/data/app/current/config.ru", {12=>#<Kgio::UNIXServer:fd 12>}] (in /data/app/releases/20140516184210)
I, [2014-05-16T13:46:27.566115 #11637] INFO -- : inherited addr=/var/run/engineyard/unicorn_afar.sock fd=12
I, [2014-05-16T13:46:27.566551 #11637] INFO -- : Refreshing Gem list
I, [2014-05-16T13:47:13.036963 #8247] INFO -- : reaped #<Process::Status: pid 8681 exit 0> worker=3
I, [2014-05-16T13:47:14.093196 #8247] INFO -- : reaped #<Process::Status: pid 8670 exit 0> worker=2
I, [2014-05-16T13:47:14.100269 #12047] INFO -- : worker=0 ready
I, [2014-05-16T13:47:15.105249 #12063] INFO -- : worker=1 ready
I, [2014-05-16T13:47:15.114038 #8247] INFO -- : reaped #<Process::Status: pid 8655 exit 0> worker=1
I, [2014-05-16T13:47:15.957970 #8247] INFO -- : reaped #<Process::Status: pid 8638 exit 0> worker=0
I, [2014-05-16T13:47:15.958159 #8247] INFO -- : master complete
I, [2014-05-16T13:47:16.087761 #12082] INFO -- : worker=2 ready
I, [2014-05-16T13:47:16.876129 #11637] INFO -- : master process ready
I, [2014-05-16T13:47:17.102994 #12095] INFO -- : worker=3 ready
And here is the first request on my rails logs:
Started GET "/" for 70.XX.XXX.XXX at 2014-05-16 13:47:51 -0700
Processing by HomeController#index as HTML
(1.1ms) SELECT ..... <regular controller/ActiveRecord queries>
Completed 304 Not Modified in 2724.8ms (ActiveRecord: 98.9ms)
First request to Rails app is very slow may be relevant.
Maybe there is a dependency that is loading / running on the first page load?
Some ideas:
Check the rails log to see if there's anything funky going on
Is this just happening for Unicorn or with other servers too?
Add log statements with time stamps to get a sense for what part of the app is taking a long time
Try using ruby prof

No error message explaining why can't connect to server

I'm following along with a screencasthttp://railscasts.com/episodes/335-deploying-to-a-vps?view=asciicastthat that instructs how to deploy to a VPS with nginx and unicorn (I'm installing a Ruby on Rails app on ubuntu). After installing the various services (nginx, postgres, unicorn, ruby) and running cap deploy:cold, my app (as expected) displayed the default nginx page, which the screencast instructs to remove in the following way so that nginx serves the production app
deployer#li349-144:~$ sudo rm /etc/nginx/sites-enabled/default
[sudo] password for deployer:
deployer#li349-144:~$ sudo service nginx restart
Restarting nginx: nginx.
I've previously deployed applications where, after removing this default page, the intended application appears. However, after I run these commands on my server this time and navigate to the ip address, the browser tells me it can't connect to the server. Not sure what was wrong, I tried to restart nginx, unicorn and postgres (all of which restarted successfully) but I got the same error message in the browser.
There's a log directory on my cloud server with a unicorn.log logfile and a production.log but neither of them indicate any problems. For example, the production.log only indicates that database migrations have been run, and this is the unicorn.log
I, [2013-07-11T23:26:57.717019 #6664] INFO -- : listening on addr=/tmp/unicorn.qbruby3.sock fd=10
I, [2013-07-11T23:26:57.717480 #6664] INFO -- : worker=0 spawning...
I, [2013-07-11T23:26:57.718428 #6664] INFO -- : worker=1 spawning...
I, [2013-07-11T23:26:57.719538 #6667] INFO -- : worker=0 spawned pid=6667
I, [2013-07-11T23:26:57.719713 #6667] INFO -- : Refreshing Gem list
I, [2013-07-11T23:26:57.722070 #6664] INFO -- : master process ready
I, [2013-07-11T23:26:57.726747 #6670] INFO -- : worker=1 spawned pid=6670
I, [2013-07-11T23:26:57.727030 #6670] INFO -- : Refreshing Gem list
I, [2013-07-11T23:27:09.930162 #6670] INFO -- : worker=1 ready
I, [2013-07-11T23:27:10.084362 #6667] INFO -- : worker=0 ready
I, [2013-07-12T01:05:52.638290 #6664] INFO -- : reloading config_file=/home/michael/apps/qbruby3/shared/config/unicorn.rb
I, [2013-07-12T01:05:52.668897 #6664] INFO -- : done reloading config_file=/home/michael/apps/qbruby3/shared/config/unicorn.rb
I, [2013-07-12T01:05:52.858858 #6664] INFO -- : reaped #<Process::Status: pid 6667 exit 0> worker=0
I, [2013-07-12T01:05:52.859032 #6664] INFO -- : worker=0 spawning...
I, [2013-07-12T01:05:52.860609 #7212] INFO -- : worker=0 spawned pid=7212
I, [2013-07-12T01:05:52.860839 #7212] INFO -- : Refreshing Gem list
I, [2013-07-12T01:05:52.875751 #6664] INFO -- : reaped #<Process::Status: pid 6670 exit 0> worker=1
I, [2013-07-12T01:05:52.875944 #6664] INFO -- : worker=1 spawning...
I, [2013-07-12T01:05:52.877405 #7215] INFO -- : worker=1 spawned pid=7215
I, [2013-07-12T01:05:52.877651 #7215] INFO -- : Refreshing Gem list
I, [2013-07-12T01:06:02.191290 #7212] INFO -- : worker=0 ready
I, [2013-07-12T01:06:02.269397 #7215] INFO -- : worker=1 ready
In this situation, what else could I check to identify the reason the app is not appearing?

Resources