0

Something simple, I'm sure but I've been searching and can't find an answer.

in brief: I want to set up a daily mailer to email a lists of tasks daily.

I have a worker (scheduled every minute, and only puts'ing for dev):

class DailyReminderWorker

    include Sidekiq::Worker
    include Sidetiq::Schedulable

    recurrence do
        hourly.minute_of_hour(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59)
    end

    def perform

        User.find_each do |user|
            @user = user.name
            puts "user name is #{@user}"
            @reminder = Remindarrr.where(user_id: user.id)

            @reminder.each do |r|
                puts r.title
            end

        end
    end 

end

I know I can call this with the following in a controller:

DailyReminderWorker.perform_async 

This works and outputs every minute but every time the page refreshes it also fires. (less useful for a daily mailer.)

How do you call the worker to queue the job without it firing immediately? Where would you put the perform.async?

Thanks a lot!

  • Are you sure the queue has enough jobs enqueued(more than the concurrent number of jobs that can be run ?) If not the enqueued job will be enqueued and will be picked up immediately for execution(within a short duration). – Alok Swain Jan 17 '20 at 10:55
  • Everytime the page refreshes the job fires; do you enqueue the job in some controller action ? To manually delay you could also do e.g. `DailyReminderWorker.perform_in(5.minutes)` (schedule the job to be enqueued after 5 minutes or whatever duration you want to delay for. – Alok Swain Jan 17 '20 at 10:58

1 Answers1

1

If you are on a Linux platform, just use cron. very easy to setup.

Fernand
  • 1,293
  • 1
  • 10
  • 18