mirror of
https://git.bsd.gay/fef/nyastodon.git
synced 2024-12-24 18:13:42 +01:00
Fix Scheduler::SubscriptionsScheduler (#2834)
* Fix Scheduler::SubscriptionsScheduler, add worker test for it * Change production log level of Sidekiq to "warn" instead of "info"
This commit is contained in:
parent
1f15a15621
commit
b8e166894b
7 changed files with 26 additions and 13 deletions
|
@ -1,7 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
class ApplicationWorker
|
|
||||||
def info(message)
|
|
||||||
Rails.logger.info("#{self.class.name} - #{message}")
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,11 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class DistributionWorker < ApplicationWorker
|
class DistributionWorker
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
|
|
||||||
def perform(status_id)
|
def perform(status_id)
|
||||||
FanOutOnWriteService.new.call(Status.find(status_id))
|
FanOutOnWriteService.new.call(Status.find(status_id))
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
info("Couldn't find the status")
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Pubsubhubbub::ConfirmationWorker
|
||||||
|
|
||||||
body = response.body.to_s
|
body = response.body.to_s
|
||||||
|
|
||||||
Rails.logger.debug "Confirming PuSH subscription for #{subscription.callback_url} with challenge #{challenge}: #{body}"
|
logger.debug "Confirming PuSH subscription for #{subscription.callback_url} with challenge #{challenge}: #{body}"
|
||||||
|
|
||||||
if mode == 'subscribe' && body == challenge
|
if mode == 'subscribe' && body == challenge
|
||||||
subscription.save!
|
subscription.save!
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Pubsubhubbub::SubscribeWorker
|
||||||
|
|
||||||
def perform(account_id)
|
def perform(account_id)
|
||||||
account = Account.find(account_id)
|
account = Account.find(account_id)
|
||||||
Rails.logger.debug "PuSH re-subscribing to #{account.acct}"
|
logger.debug "PuSH re-subscribing to #{account.acct}"
|
||||||
::SubscribeService.new.call(account)
|
::SubscribeService.new.call(account)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,9 +5,9 @@ class Scheduler::SubscriptionsScheduler
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Rails.logger.debug 'Queueing PuSH re-subscriptions'
|
logger.info 'Queueing PuSH re-subscriptions'
|
||||||
|
|
||||||
expiring_accounts.pluck(:id) do |id|
|
expiring_accounts.pluck(:id).each do |id|
|
||||||
Pubsubhubbub::SubscribeWorker.perform_async(id)
|
Pubsubhubbub::SubscribeWorker.perform_async(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,6 +87,7 @@ Rails.application.configure do
|
||||||
|
|
||||||
config.to_prepare do
|
config.to_prepare do
|
||||||
StatsD.backend = StatsD::Instrument::Backends::NullBackend.new if ENV['STATSD_ADDR'].blank?
|
StatsD.backend = StatsD::Instrument::Backends::NullBackend.new if ENV['STATSD_ADDR'].blank?
|
||||||
|
Sidekiq::Logging.logger.level = Logger::WARN
|
||||||
end
|
end
|
||||||
|
|
||||||
config.action_dispatch.default_headers = {
|
config.action_dispatch.default_headers = {
|
||||||
|
|
19
spec/workers/scheduler/subscriptions_scheduler_spec.rb
Normal file
19
spec/workers/scheduler/subscriptions_scheduler_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Scheduler::SubscriptionsScheduler do
|
||||||
|
subject { Scheduler::SubscriptionsScheduler.new }
|
||||||
|
|
||||||
|
let!(:expiring_account1) { Fabricate(:account, subscription_expires_at: 20.minutes.from_now, domain: 'example.com', followers_count: 1, hub_url: 'http://hub.example.com') }
|
||||||
|
let!(:expiring_account2) { Fabricate(:account, subscription_expires_at: 4.hours.from_now, domain: 'example.org', followers_count: 1, hub_url: 'http://hub.example.org') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_request(:post, 'http://hub.example.com/').to_return(status: 202)
|
||||||
|
stub_request(:post, 'http://hub.example.org/').to_return(status: 202)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 're-subscribes for all expiring accounts' do
|
||||||
|
subject.perform
|
||||||
|
expect(a_request(:post, 'http://hub.example.com/')).to have_been_made.once
|
||||||
|
expect(a_request(:post, 'http://hub.example.org/')).to have_been_made.once
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue