From e17f9d5e1ad63dc61085b4288f349f8a6f75361d Mon Sep 17 00:00:00 2001 From: Eugen Date: Sun, 16 Apr 2017 12:53:58 +0200 Subject: [PATCH] Unite all mandatory rake tasks in mastodon:daily (#1887) * Unite all mandatory rake tasks in mastodon:daily Add mastodon:media:remove_remote task Make mastodon:maintenance:add_static_avatars more resilient to exceptions * Fix typo in task description --- lib/tasks/mastodon.rake | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake index 54980634d35..b4773027401 100644 --- a/lib/tasks/mastodon.rake +++ b/lib/tasks/mastodon.rake @@ -1,6 +1,16 @@ # frozen_string_literal: true namespace :mastodon do + desc 'Execute daily tasks' + task :daily do + Rake::Task['mastodon:feeds:clear'].invoke + Rake::Task['mastodon:media:clear'].invoke + Rake::Task['mastodon:users:clear'].invoke + + Rake::Task['mastodon:push:refresh'].invoke + end + + desc 'Turn a user into an admin, identified by the USERNAME environment variable' task make_admin: :environment do include RoutingHelper @@ -13,12 +23,13 @@ namespace :mastodon do desc 'Manually confirms a user with associated user email address stored in USER_EMAIL environment variable.' task confirm_email: :environment do email = ENV.fetch('USER_EMAIL') - user = User.where(email: email).first + user = User.find_by(email: email) + if user user.update(confirmed_at: Time.now.utc) - puts "User #{email} confirmed." + puts "#{email} confirmed" else - abort "User #{email} not found." + abort "#{email} not found" end end @@ -32,6 +43,13 @@ namespace :mastodon do task remove_silenced: :environment do MediaAttachment.where(account: Account.silenced).find_each(&:destroy) end + + desc 'Remove cached remote media attachments that are older than a week' + task remove_remote: :environment do + MediaAttachment.where.not(remote_url: '').where('created_at < ?', 1.week.ago).find_each do |media| + media.file.destroy + end + end end namespace :push do @@ -60,7 +78,7 @@ namespace :mastodon do end end - desc 'Clears all timelines so that they would be regenerated on next hit' + desc 'Clears all timelines' task clear_all: :environment do Redis.current.keys('feed:*').each { |key| Redis.current.del(key) } end @@ -126,8 +144,13 @@ namespace :mastodon do Rails.logger.debug 'Generating static avatars/headers for GIF ones...' Account.unscoped.where(avatar_content_type: 'image/gif').or(Account.unscoped.where(header_content_type: 'image/gif')).find_each do |account| - account.avatar.reprocess! - account.header.reprocess! + begin + account.avatar.reprocess! + account.header.reprocess! + rescue StandardError => e + Rails.logger.error "Error while generating static avatars/headers for account #{account.id}: #{e}" + next + end end Rails.logger.debug 'Done!'