* Registers the Github AcocuntSuspended & RepositoryUnavailable errors Adds the above-mentioned errors to the list of known errors raised by Octokit as to make possible for the rest of the application to specifically trap those. * Makes the RepoSyncWorker error handling rely on types The current implementation attempted to parse the error message to determine if the error reported by Github's API can/should be handled, this commit changes the implementation so that the exception type is used instead.
38 lines
1.1 KiB
Ruby
38 lines
1.1 KiB
Ruby
module GithubRepos
|
|
class RepoSyncWorker
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: :low_priority, retry: 10, lock: :until_executing
|
|
|
|
def perform(repo_id)
|
|
repo = GithubRepo.find_by(id: repo_id)
|
|
return unless repo
|
|
|
|
user = repo.user
|
|
return unless user.identities.github.exists?
|
|
|
|
begin
|
|
client = Github::OauthClient.for_user(user)
|
|
fetched_repo = client.repository(repo.info_hash[:full_name])
|
|
|
|
repo.update!(
|
|
github_id_code: fetched_repo.id,
|
|
name: fetched_repo.name,
|
|
description: fetched_repo.description,
|
|
language: fetched_repo.language,
|
|
fork: fetched_repo.fork,
|
|
bytes_size: fetched_repo.size,
|
|
watchers_count: fetched_repo.watchers,
|
|
stargazers_count: fetched_repo.stargazers_count,
|
|
info_hash: fetched_repo.to_hash,
|
|
)
|
|
repo.user&.touch(:github_repos_updated_at)
|
|
rescue Github::Errors::NotFound,
|
|
Github::Errors::Unauthorized,
|
|
Github::Errors::AccountSuspended,
|
|
Github::Errors::RepositoryUnavailable
|
|
repo.destroy
|
|
end
|
|
end
|
|
end
|
|
end
|