about summary refs log tree commit diff
path: root/lib/tasks/mastodon.rake
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tasks/mastodon.rake')
-rw-r--r--lib/tasks/mastodon.rake35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index 54980634d..b47730274 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!'