Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Mastodon アカウント画像再ダウンロードタスク / Re-download deleted account images task.
- # lib/tasks/test.rake
- # RAILS_ENV=production bundle exec rake test:account_images:recover
- #
- # なぜかあまり大量だと too many open files が出る(再実行で続きから実行される)
- # Sometime occurs "too many open files" error. (You need re-execute task.)
- # プログレス表示とかは無い / no progress display.
- # S3などを使用している場合かなり多めのリクエストをS3へ飛ばすことになるのでコストに注意。
- # If you use cloud strage, this task produces a lot of GET request to storage. (for checking image file exists).
- namespace :test do
- namespace :account_images do
- desc 'download missing avatars & headers'
- task recover: :environment do
- Account.remote.each do |a|
- begin
- changed = false
- if a.avatar.present? || a.avatar_remote_url.present?
- unless a.avatar.exists?
- a.avatar = a.avatar_remote_url
- changed = true
- end
- end
- if a.header.present? || a.header_remote_url.present?
- unless a.header.exists?
- a.header = a.header_remote_url
- changed = true
- end
- end
- if changed
- a.save
- puts "Recovered account images for @#{a.username}@#{a.domain}"
- sleep 0.3
- end
- rescue OpenURI::HTTPError, SocketError, Timeout::Error, OpenSSL::SSL::SSLError, Errno::ECONNRESET
- ; # ignore errors
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement