You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. namespace :mastodon do
  3. namespace :media do
  4. desc 'Removes media attachments that have not been assigned to any status for longer than a day'
  5. task clear: :environment do
  6. MediaAttachment.where(status_id: nil).where('created_at < ?', 1.day.ago).find_each(&:destroy)
  7. end
  8. end
  9. namespace :push do
  10. desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
  11. task clear: :environment do
  12. include RoutingHelper
  13. Account.remote.without_followers.where.not(subscription_expires_at: nil).find_each do |a|
  14. Rails.logger.debug "PuSH unsubscribing from #{a.acct}"
  15. begin
  16. a.subscription(api_subscription_url(a.id)).unsubscribe
  17. rescue HTTP::Error, OpenSSL::SSL::SSLError
  18. Rails.logger.debug "PuSH unsubscribing from #{a.acct} failed due to an HTTP or SSL error"
  19. ensure
  20. a.update!(secret: '', subscription_expires_at: nil)
  21. end
  22. end
  23. end
  24. desc 'Re-subscribes to soon expiring PuSH subscriptions'
  25. task refresh: :environment do
  26. Account.expiring(1.day.from_now).find_each do |a|
  27. Rails.logger.debug "PuSH re-subscribing to #{a.acct}"
  28. SubscribeService.new.call(a)
  29. end
  30. end
  31. end
  32. namespace :feeds do
  33. desc 'Clears all timelines so that they would be regenerated on next hit'
  34. task clear: :environment do
  35. Redis.current.keys('feed:*').each { |key| Redis.current.del(key) }
  36. end
  37. end
  38. namespace :graphs do
  39. desc 'Syncs all follow relationships to Neo4J'
  40. task sync: :environment do
  41. Follow.find_each(&:sync!)
  42. end
  43. end
  44. end