Class: Appstats::ResultJob
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Appstats::ResultJob
- Defined in:
- lib/appstats/result_job.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
- #should_run ⇒ Object
Class Method Details
.require_third_party_queries(queries) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/appstats/result_job.rb', line 21 def self.require_third_party_queries(queries) if queries.nil? Appstats.log(:info, "No third party query provided.") return end queries.each do |q| if q[:path].nil? Appstats.log(:info, "Please specify the third party query ':path'.") next end unless File.exists?(q[:path]) Appstats.log(:info, "Unable to find third party query [#{q[:path]}].") next end Appstats.log(:info, "Loaded to third party query [#{q[:path]}].") require q[:path] end end |
.run ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/appstats/result_job.rb', line 42 def self.run count = 0 all = Appstats.rails3? ? ResultJob.where("frequency <> 'once' or last_run_at IS NULL").all : ResultJob.find(:all, :conditions => "frequency <> 'once' or last_run_at IS NULL") if all.size == 0 Appstats.log(:info, "No result jobs to run.") return count end Appstats.log(:info, "About to analyze #{all.size} result job(s).") all.each do |job| if job.should_run Appstats.log(:info, " - Job #{job.name} run [ID #{job.id}, FREQUENCY #{job.frequency}, QUERY #{job.query}]") query = Appstats::Query.new(:name => job.name, :result_type => "result_job", :query => job.query, :query_type => job.query_type) query.run job.last_run_at = Time.now job.save count += 1 else Appstats.log(:info, " - Job #{job.name} NOT run [ID #{job.id}, FREQUENCY #{job.frequency}, QUERY #{job.query}]") end end Appstats.log(:info, "Ran #{count} query(ies).") count end |
Instance Method Details
#==(o) ⇒ Object Also known as: eql?
16 17 18 |
# File 'lib/appstats/result_job.rb', line 16 def ==(o) o.class == self.class && o.send(:state) == state end |
#should_run ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/appstats/result_job.rb', line 8 def should_run return true if frequency == "once" && last_run_at.nil? period = { "daily" => :beginning_of_day, "weekly" => :beginning_of_week, "monthly" => :beginning_of_month, "quarterly" => :beginning_of_quarter, "yearly" => :beginning_of_year }[frequency] return false if period.nil? return true if last_run_at.nil? last_run_at.send(period) <= (Time.now.send(period) - 1.day).send(period) end |