Skip to content

Instantly share code, notes, and snippets.

@zemagno
Created February 17, 2016 14:45
Show Gist options
  • Save zemagno/fcd470b2fee9b5fd13dc to your computer and use it in GitHub Desktop.
Save zemagno/fcd470b2fee9b5fd13dc to your computer and use it in GitHub Desktop.
namespace :scheduler do
desc "Scheduler..."
task :go => :environment do
Scheduler.go
puts "Scheduler.go - #{Time.now} - Success!"
end
end
class Scheduler < ActiveRecord::Base
attr_accessible :job, :when, :ordem
default_scope order('ordem ASC')
def self.go
hoje = Time.now()
Scheduler.all.each do |x|
if (((x.when.include? "[#{hoje.day}]") || (x.when.include? ["[dom]","[seg]","[ter]","[qua]","[qui]","[sex]","[sab]"][hoje.wday])) and x.when.include? "[H#{hoje.hour}]")
puts x.job
Producao.dispatcherJob(x.job)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment