diff --git a/lib/tasks/emails.rake b/lib/tasks/appfab_emails.rake similarity index 75% rename from lib/tasks/emails.rake rename to lib/tasks/appfab_emails.rake index 4aa50ad..397a118 100644 --- a/lib/tasks/emails.rake +++ b/lib/tasks/appfab_emails.rake @@ -1,8 +1,8 @@ namespace :appfab do namespace :emails do - task :send_notifications_digest => :environment do + desc 'sends notification digests to all users' + task :send_notifications_digest => :full_environment do User.with_state(:visible).find_each do |user| - require 'notification/mailer' next unless user.notifications.unread.count > 0 notifications = user.notifications.unread.by_most_recent.limit(25) diff --git a/lib/tasks/appfab_ideas.rake b/lib/tasks/appfab_ideas.rake index 7381e91..8f26910 100644 --- a/lib/tasks/appfab_ideas.rake +++ b/lib/tasks/appfab_ideas.rake @@ -1,15 +1,14 @@ namespace :appfab do namespace :ideas do desc 'updates star ratings for all ideas' - task :update_stars_cache => :environment do - require "account" + task :update_stars_cache => :full_environment do Account.find_each do |account| Idea.update_star_cache(account:account) end end desc 'updates counter caches' - task :update_counts => :environment do + task :update_counts => :full_environment do Idea.find_each do |idea| idea.update_column :comments_count, idea.comments.count idea.update_column :votes_cache, idea.votes.count @@ -17,8 +16,7 @@ namespace :appfab do end desc 'removes bookmarks for old live ideas' - task :bookmark_cleanup => :environment do - require "bookmark_cleanup_service" + task :bookmark_cleanup => :full_environment do BookmarkCleanupService.new.run end end diff --git a/lib/tasks/appfab_users.rake b/lib/tasks/appfab_users.rake new file mode 100644 index 0000000..dcd43c7 --- /dev/null +++ b/lib/tasks/appfab_users.rake @@ -0,0 +1,8 @@ +namespace :appfab do + namespace :users do + desc 'Saves last-seen timestamps from cache to DB' + task :update_last_seen_at => :full_environment do + User.find_each { |user| user.update_last_seen_at! } + end + end +end \ No newline at end of file diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index 1346d10..502862e 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -2,8 +2,8 @@ namespace :data do - desc 'Re-saves all stored files to make sure nu chunk is larger than a 65k BLOB' - task :fix_storage_chunks => :environment do + desc 'Re-saves all stored files to make sure no chunk is larger than a 65k BLOB' + task :fix_storage_chunks => :full_environment do Storage::File.find_each do |storage_file| storage_file.transaction do old_data = storage_file.data diff --git a/lib/tasks/full_environment.rake b/lib/tasks/full_environment.rake new file mode 100644 index 0000000..794f3d7 --- /dev/null +++ b/lib/tasks/full_environment.rake @@ -0,0 +1,5 @@ +desc "Eager loads the entire Rails environment" +# see http://stackoverflow.com/questions/4300240/rails-3-rake-task-cant-find-model-in-production +task :full_environment => :environment do + Rails.application.eager_load! +end \ No newline at end of file diff --git a/lib/tasks/users.rake b/lib/tasks/users.rake deleted file mode 100644 index c07c5d7..0000000 --- a/lib/tasks/users.rake +++ /dev/null @@ -1,11 +0,0 @@ -# encoding: utf-8 - -namespace :users do - - desc 'Saves last-seen timestamps from cache to DB' - task :update_last_seen_at => :environment do - User.find_each do |user| - user.update_last_seen_at! - end - end -end