[deploy] Add temporary RSS reader worker to gather monitoring data (#11037)

This commit is contained in:
rhymes 2020-10-23 19:02:08 +02:00 committed by GitHub
parent 17535cd90b
commit b6762fcc7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# NOTE: [rhymes]
# This script will soon be removed. We need it to collect monitoring data on
# Datadog about the production behavior of the `RssReader` class
module Articles
class DevRssReaderWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority, retry: 10
def perform
return unless SiteConfig.community_name == "DEV"
return if Rails.cache.read("cancel_rss_job").present?
# we force fetch to have realistic data
RssReader.get_all_articles(force: true)
end
end
end

View file

@ -0,0 +1,39 @@
require "rails_helper"
RSpec.describe Articles::DevRssReaderWorker, type: :worker do
let(:worker) { subject }
include_examples "#enqueues_on_correct_queue", "medium_priority"
describe "#perform" do
it "does not call the RssReader for non DEV communities" do
allow(SiteConfig).to receive(:community_name).and_return("NotDEV")
allow(RssReader).to receive(:get_all_articles)
worker.perform
expect(RssReader).not_to have_received(:get_all_articles)
end
it "does not call the RssReader if the cache instructs it to cancel" do
allow(SiteConfig).to receive(:community_name).and_return("DEV")
allow(Rails.cache).to receive(:read).with("cancel_rss_job").and_return("true")
allow(RssReader).to receive(:get_all_articles)
worker.perform
expect(RssReader).not_to have_received(:get_all_articles)
end
it "calls the RssReader to get all articles" do
allow(SiteConfig).to receive(:community_name).and_return("DEV")
allow(Rails.cache).to receive(:read).with("cancel_rss_job").and_return(nil)
allow(RssReader).to receive(:get_all_articles)
worker.perform
expect(RssReader).to have_received(:get_all_articles).with(force: true)
end
end
end