[deploy] Refactor:Fetch New Github Repos From Sidekiq Cron (#9986)
This commit is contained in:
parent
24a3b50d4a
commit
0947256f13
5 changed files with 32 additions and 6 deletions
|
|
@ -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)
|
||||
|
|
|
|||
11
app/workers/github_repos/update_latest_worker.rb
Normal file
11
app/workers/github_repos/update_latest_worker.rb
Normal 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
|
||||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
15
spec/workers/github_repos/update_latest_worker_spec.rb
Normal file
15
spec/workers/github_repos/update_latest_worker_spec.rb
Normal 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
|
||||
Loading…
Add table
Reference in a new issue