[deploy] Refactor:Fetch New Github Repos From Sidekiq Cron (#9986)

This commit is contained in:
Molly Struve 2020-08-25 12:42:33 -05:00 committed by GitHub
parent 24a3b50d4a
commit 0947256f13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 6 deletions

View file

@ -27,8 +27,8 @@ class GithubRepo < ApplicationRecord
end
def self.update_to_latest
where("updated_at < ?", 1.day.ago).find_each do |repo|
user = User.find_by(id: repo.user_id)
where("updated_at < ?", 26.hours.ago).includes(:user).find_each do |repo|
user = repo.user
next unless user
client = Github::OauthClient.for_user(user)

View file

@ -0,0 +1,11 @@
module GithubRepos
class UpdateLatestWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority, retry: 10
def perform
GithubRepo.update_to_latest
end
end
end

View file

@ -104,3 +104,7 @@ sync_credits_counter_cache:
get_podcast_episodes:
cron: "5 * * * *" # every hour, 5 min after the hour
class: "Podcasts::EnqueueGetEpisodesWorker"
update_latest_github_repos:
cron: "30 16 * * *" # daily at 4:30 pm UTC
class: "GithubRepos::UpdateLatestWorker"

View file

@ -5,7 +5,3 @@ task fetch_all_rss: :environment do
RssReader.get_all_articles(force: false) # don't force fetch. Fetch "random" subset instead of all of them.
end
task github_repo_fetch_all: :environment do
GithubRepo.update_to_latest
end

View file

@ -0,0 +1,15 @@
require "rails_helper"
RSpec.describe GithubRepos::UpdateLatestWorker, type: :worker do
let(:worker) { subject }
include_examples "#enqueues_on_correct_queue", "medium_priority"
describe "#perform" do
it "update latest GithubRepos" do
allow(GithubRepo).to receive(:update_to_latest)
worker.perform
expect(GithubRepo).to have_received(:update_to_latest)
end
end
end