Fix Scheduler::SubscriptionsScheduler (#2834)
* Fix Scheduler::SubscriptionsScheduler, add worker test for it * Change production log level of Sidekiq to "warn" instead of "info"master
parent
1f15a15621
commit
b8e166894b
@ -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 |
||||
|
||||
class DistributionWorker < ApplicationWorker |
||||
class DistributionWorker |
||||
include Sidekiq::Worker |
||||
|
||||
def perform(status_id) |
||||
FanOutOnWriteService.new.call(Status.find(status_id)) |
||||
rescue ActiveRecord::RecordNotFound |
||||
info("Couldn't find the status") |
||||
true |
||||
end |
||||
end |
||||
|
@ -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 new issue