rubycronpadrino

How to customize cron job in ruby application?


I have been developing a backend with padrino ruby framework and I would like to build a cron job.

This is what I have done.

inside schedule.rb

 every 1.minute do
    rake "cronjob"
 end

/tasks/cronjob.rake

Here I added my custom tasks. and this will be to long to add here.

So I wrote only error happening parts

performances = Performance.left_join(:slots, id: :slot_id).where(Sequel.~(status: ModelA::Api.settings.pending),Sequel[:slots][:from]>oneweekbefore,Sequel[:slots][:to]<onemonthafter+1.day)
....

begin
  data = {}
  data[:from] = "** <postmaster@**.mailgun.org>"
  data[:to] = email
  data[:subject] = subject
  data[:html] = render 'mails/sendemailbasedontime',:locals => { :data => localdata }
  RestClient.post GigabitArtist::Api.settings.mailgun_domain, data
    rescue => exception
      puts exception.inspect
    end
end

I got these errors:

SEQUEL DEPRECATION WARNING: Passing multiple arguments as filter arguments when not using a conditions specifier ([#:!=, @args=>[:status, "pending"]>, #:>, @args=>[#"slots", @column=>:from>, Sat, 02 Dec 2017]>, #:<, @args=>[#"slots", @column=>:to>, Wed, 10 Jan 2018]>]) is deprecated and will be removed in Sequel 5. Pass the arguments to separate filter methods or use Sequel.& to combine them. /Users/whitesnow/.rvm/gems/ruby-2.4.1/gems/sequel-4.46.0/lib/sequel/dataset/query.rb:1296:in filter_expr' /Users/whitesnow/.rvm/gems/ruby-2.4.1/gems/sequel-4.46.0/lib/sequel/dataset/query.rb:1249:in add_filter' /Users/whitesnow/.rvm/gems/ruby-2.4.1/gems/sequel-4.46.0/lib/sequel/dataset/query.rb:1034:in where' /Volumes/Data/Work/RBP/GAB/tasks/cronjob.rake:12:inblock in ' /Users/whitesnow/.rvm/gems/ruby-2.4.1@global/gems/rake-12.0.0/lib/rake/task.rb:250:in block in execute' /Users/whitesnow/.rvm/gems/ruby-2.4.1@global/gems/rake-12.0.0/lib/rake/task.rb:250:in each' /Users/whitesnow/.rvm/gems/ruby-2.4.1@global/gems/rake-12.0.0/lib/rake/task.rb:250:in execute' /Users/whitesnow/.rvm/gems/ruby-2.4.1@global/gems/rake-12.0.0/lib/rake/task.rb:194:in block in invoke_with_call_chain' /Users/whitesnow/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/monitor.rb:214:in mon_synchronize' /Users/whitesnow/.rvm/gems/ruby-2.4.1@global/gems/rake-12.0.0/lib/rake/task.rb:187:in invoke_with_call_chain'

I think errors are from sequel querying and

data[:html] = render 'mails/sendemailbasedontime',:locals => { :data => localdata }

ofcourse, this query was tested in other .rb file and I tested with raw sql. for example, I tested this tasks inside get request hander of test.rb controller. and it does work well I would like to know if I can use render function inside task. I searched all day for this problem with no success. Any advice will be big help for me. Thank you very much.


Solution

  • As the deprecation warning states, you are passing multiple arguments to a filter method. The simplest fix would be to call a filter method separately for each argument:

    performances = Performance.
      left_join(:slots, id: :slot_id).
      exclude(status: ModelA::Api.settings.pending).
      where(Sequel[:slots][:from]>oneweekbefore).
      where(Sequel[:slots][:to]<onemonthafter+1.day)