Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:36:45+00:00 2026-05-16T10:36:45+00:00

I read the documentation on workers and delayed_job and couldn’t follow exactly, so wanted

  • 0

I read the documentation on workers and delayed_job and couldn’t follow exactly, so wanted to get head-start with some strategy and sample code.

I have a controller which I use to send emails one by one. Now each day I want to check which emails need to be sent for the day, and then send them through heroku as a delayed_job.

How do I begin to approach this? thanks.

This is what I’m coming up with based on the answers:

Using the ‘whenever’ gem, I created the following schedule.rb

  every 1.day, :at => '4:30 am' do

    heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS'])
    heroku.set_workers(ENV['HEROKU_APP'], 1)

    Contact.all.each do |contact|
      contact_email = contact.email_today

      unless contact.email_today == "none"
        puts contact.first_name
        puts contact_email.days
        puts contact.date_entered

        Delayed::Job.enqueue OutboundMailer.deliver_campaign_email(contact,contact_email)
      end

    end

    heroku.set_workers(ENV['HEROKU_APP'], 0)
  end

To determine whether I should send an email today or not, I created the method for contact.rb:

  def email_today

    next_event_info = self.next_event_info # invokes method for contact

    next_event = next_event_info[:event]
    delay = next_event_info[:delay]

    if next_event.class.name == "Email" && from_today(self, next_event.days) + delay < 0 #helper from_today
      return next_event      
    else
      return "none"
    end

  end

Does this look right? I am developing on windows and deploying to heroku so don’t know how to test it…thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:36:46+00:00Added an answer on May 16, 2026 at 10:36 am

    If you’re sending emails out once a day, you probably want to start by add the cron addon to your application, which will fire a rake task once-per day.

    Obviously, you’ll also need to add the delayed_job plugin (http://docs.heroku.com/delayed-job). In addition, your app will need to be running at least one worker.

    Then it’s just a matter of doing your mail work from within your cron rake task. For example, if you had a mailer called ‘UserMailer’, your cron could look something like this:

    #lib/cron.rb
    task :cron => :environment do
      User.all.each do |user|
        Delayed::Job.enqueue UserMailer.deliver_notification(user)
      end
    end
    

    If you’re only using background tasks to send these emails, you could probably add also some logic in your cron task, and your mailer methods to add and remove workers as required, which will save you having to pay for the workers while they’re not in use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read documentation of cache_lite but couldn't found any option regarding to manage cache
Having read the documentation and many many articles I believe the following should work
What does InputStream.available() do in Java ? I read the documentation, but I still
Im trying to write a Filter for my web-app. I read [the documentation][1], and
I am writing a package in R and I would appreciate some example bash
I would like to schedule a cron task to run every hour, but only
I am new to using multiple targets in a xcode project and have hit
I am developing a library for further usage in other libraries or final products.
I have to do this: 1:CGRect originalSubviewFrame = subview.frame; 2:view.frame = (CGRect)newFrame; 3:subview.frame =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.