POC: use Sidekiq.perform_bulk for Github repos (#16293)

This commit is contained in:
Michael Kohl 2022-01-26 09:11:07 +07:00 committed by GitHub
parent 4b4d8a7234
commit 67f68b1cc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View file

@ -27,9 +27,8 @@ class GithubRepo < ApplicationRecord
end
def self.update_to_latest
where("updated_at < ?", 26.hours.ago).ids.each do |repo_id|
GithubRepos::RepoSyncWorker.perform_async(repo_id)
end
ids = where(updated_at: ...26.hours.ago).ids.map { |id| [id] }
GithubRepos::RepoSyncWorker.perform_bulk(ids)
end
private

View file

@ -81,9 +81,9 @@ RSpec.describe GithubRepo, type: :model do
describe "::update_to_latest" do
it "enqueues GithubRepos::RepoSyncWorker" do
repo.update(updated_at: 1.week.ago)
allow(GithubRepos::RepoSyncWorker).to receive(:perform_async)
allow(GithubRepos::RepoSyncWorker).to receive(:perform_bulk)
described_class.update_to_latest
expect(GithubRepos::RepoSyncWorker).to have_received(:perform_async).with(repo.id)
expect(GithubRepos::RepoSyncWorker).to have_received(:perform_bulk).with([[repo.id]])
end
end
end