简体   繁体   中英

Why does this rake task appear to not be running in Heroku?

So I tried running a rake task:

heroku run:detached rake some_task --app myproductionapp

Heroku told me to view the logs with heroku logs -p run.8334 -a myproductionapp

When I run that logging command in my console, nothing appears. This means the task didn't run (or does it?). On the professional dyno plan, I have 1 web at P_L level, 1 clock at 1x level, and 1 sidekiq dyno at P_L level running. Do I need to setup a worker dyno?

To test out if it's something obvious:

So when I do a test with Mailinator and call the function I'm using to email a user one time, I get an actual "processed" message such as below and I see the email message in Mailinator.:

MyEmailer#send_this_message: processed outbound mail in 407.3ms
=> #<ActionMailer::Base::NullMail:0x007gg91b5700a0>

When I try on production I don't get the processed message response, I only get the ActionMailer::Base::NullMail as below.

 => #<ActionMailer::Base::NullMail:0x007gg91b5700a0>

Mailing setup for staging:

 config.action_mailer.default_url_options = { :host => ENV['STAGING_HOST'] }
  # ActionMailer Config
  # Setup for production - deliveries, no errors raised
  config.action_mailer.delivery_method = :smtp
  #config.action_mailer.perform_deliveries = true
  #config.action_mailer.raise_delivery_errors = false
  #config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
    :address    => "smtp.mandrillapp.com",
    :port       => 587,
    :user_name  => ENV['MANDRILLUSER'],
    :password   => ENV['MANDRILL_KEY'],
    :domain     => 'heroku.com'

Mailing setup for production:

  # ActionMailer Config
  # Setup for production - deliveries, no errors raised
  config.action_mailer.delivery_method = :smtp
  #config.action_mailer.perform_deliveries = true
  #config.action_mailer.raise_delivery_errors = false
  #config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
    :address    => "smtp.mandrillapp.com",
    :port       => 587,
    :user_name  => ENV['MANDRILLUSER'],
    :password   => ENV['MANDRILL_KEY'],
    :domain     => 'productionapp.com',
    :enable_startls_auto => true
  }

Well this is very weird, but this may be happening due to an error in your task, check the whole logs heroku logs -a myproductionapp

For answer your question, you do not need any worker dyno, those are for background jobs, if you run the task manually then you do not need a worker, for example if you install "heroku scheduler" addon, then you can program your cron to run the task every amount of time without the need of a worker.

Update

Thanks to the new details you added to your question, well in your production configuration you are missing the host, in your staging you have:

config.action_mailer.default_url_options = { :host => ENV['STAGING_HOST'] }

Well you need to add here your production host, you can add it manually:

config.action_mailer.default_url_options = { :host => 'http://yourproductionapp.com' }

or using an environment variable:

config.action_mailer.default_url_options = { :host => ENV['PRODUCTION_HOST'] }

make sure your environment variable has the correct value in your heroku production app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM