Add tasks to generate and expire stats cache
We're generating stats every 2 hours because it's less than the time it will take to generate stats for every process. Once stats are generated, this task should take less than a second. The regenerate task has been added so we can manually execute it.
This commit is contained in:
@@ -27,6 +27,10 @@ every 1.day, at: "5:00 am" do
|
|||||||
rake "-s sitemap:refresh"
|
rake "-s sitemap:refresh"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
every 2.hours do
|
||||||
|
rake "-s stats:generate"
|
||||||
|
end
|
||||||
|
|
||||||
# Temporally not send dashboard's notifications
|
# Temporally not send dashboard's notifications
|
||||||
# every 1.day, at: "7:00 am" do
|
# every 1.day, at: "7:00 am" do
|
||||||
# rake "dashboards:send_notifications"
|
# rake "dashboards:send_notifications"
|
||||||
|
|||||||
24
lib/tasks/stats.rake
Normal file
24
lib/tasks/stats.rake
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
namespace :stats do
|
||||||
|
desc "Generates stats which are not cached yet"
|
||||||
|
task generate: :environment do
|
||||||
|
Budget.find_each do |budget|
|
||||||
|
Budget::Stats.new(budget).generate
|
||||||
|
print "."
|
||||||
|
end
|
||||||
|
|
||||||
|
Poll.find_each do |poll|
|
||||||
|
Poll::Stats.new(poll).generate
|
||||||
|
print "."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Expires stats cache"
|
||||||
|
task expire_cache: :environment do
|
||||||
|
[Budget, Poll].each do |model_class|
|
||||||
|
model_class.find_each { |record| record.find_or_create_stats_version.touch }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Deletes stats cache and generates it again"
|
||||||
|
task regenerate: [:expire_cache, :generate]
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user