about summary refs log tree commit diff
path: root/lib/tasks
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-20 00:39:03 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-20 00:43:36 +0200
commit059ebbf48dc56971b88e26a15303a75643de8b98 (patch)
treef0d46b941f298912094fe5a87b192d6fa8d4d304 /lib/tasks
parent1245ee42fb9f689ffa4956f42f44a7ab75e19075 (diff)
Separate PuSH subscriptions from following, add mastodon:push:refresh task,
respect hub.lease_seconds (fix #46)
Diffstat (limited to 'lib/tasks')
-rw-r--r--lib/tasks/mastodon.rake11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/tasks/mastodon.rake b/lib/tasks/mastodon.rake
index f59cdfcae..5bc056a56 100644
--- a/lib/tasks/mastodon.rake
+++ b/lib/tasks/mastodon.rake
@@ -11,9 +11,16 @@ namespace :mastodon do
   namespace :push do
     desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
     task clear: :environment do
-      Account.where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0').where.not(domain: nil).find_each do |a|
+      Account.remote.without_followers.find_each do |a|
         a.subscription('').unsubscribe
-        a.update!(verify_token: '', secret: '')
+        a.update!(verify_token: '', secret: '', subscription_expires_at: nil)
+      end
+    end
+
+    desc 'Re-subscribes to soon expiring PuSH subscriptions'
+    task refresh: :environment do
+      Account.expiring(1.day.from_now).find_each do |a|
+        SubscribeService.new.(a)
       end
     end
   end