0

I am writing a whenever runner defined in the Schedule model like this;

def self.scheduled_jobs   
    jobs = Schedule.where(execution_time <= Time.now )
      if !jobs.nil?
      jobs.each do |job|
        task = Schedule.find(job)
        MessageWorker.perform_async(task.message_id, task.lists, task.user_id)
        task.destroy
      end
   end
end

There is something wrong with the query here;

jobs = Schedule.where(execution_time <= Time.now )

And advice on how i can write it well?

in the console the response is ;

NameError: undefined local variable or methodexecution_time' for main:Object`

Overall any advice on how to improve the code?

The whenever cron job is here;

set :output, "/log/cron_log.log"
every 5.minute do
   runner "Schedule.scheduled_jobs"
end
acacia
  • 1,375
  • 1
  • 14
  • 40

1 Answers1

0

Assuming that the column execution_time does exist, try this:

Schedule.where('execution_time <= ?', Time.now)

On a side note:

It seems you are passing in task.lists to the worker, but shouldn't that be task.list_ids? Passing model objects to a worker is bad practice, pass ids instead.

zwippie
  • 15,050
  • 3
  • 39
  • 54