diff --git a/Gemfile b/Gemfile index c7efff7..c1b0d91 100644 --- a/Gemfile +++ b/Gemfile @@ -14,8 +14,10 @@ gem 'tweetkit', github: 'julianfssen/tweetkit' # for twitter v2 api support gem 'nokogiri' gem 'graphql' gem 'graphql-client' +gem 'retryable' gem 'rubocop' gem 'rubocop-rails' +gem 'faktory_worker_ruby' # Use postgres as the database for Active Record gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 3ca0aac..d9c3d6f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -111,6 +111,7 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.10) + connection_pool (2.2.5) crass (1.0.6) digest (3.1.0) domain_name (0.5.20190701) @@ -118,6 +119,8 @@ GEM equalizer (0.0.11) erubi (1.10.0) execjs (2.8.1) + faktory_worker_ruby (1.1.1) + connection_pool (~> 2.2, >= 2.2.2) faraday (1.9.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -280,6 +283,7 @@ GEM http-cookie (>= 1.0.2, < 2.0) mime-types (>= 1.16, < 4.0) netrc (~> 0.8) + retryable (3.0.5) rexml (3.2.5) rubocop (1.27.0) parallel (~> 1.10) @@ -380,6 +384,7 @@ DEPENDENCIES capybara (>= 2.15) chromedriver-helper coffee-rails (~> 4.2) + faktory_worker_ruby git graphql graphql-client @@ -397,6 +402,7 @@ DEPENDENCIES rails (~> 7.0.0) railties rest-client + retryable rubocop rubocop-rails sass-rails diff --git a/docker-compose.yml b/docker-compose.yml index 2a06d71..38cbe5d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,4 +17,12 @@ services: - "3000:3000" depends_on: - db + faktory: + image: contribsys/faktory:latest + ports: + - "7419:7419" + - "7420:7420" + volumes: + - ./tmp/faktory:/var/lib/faktory + diff --git a/lib/github_api/owner_repos.rb b/lib/github_api/owner_repos.rb index f284a4d..715b263 100644 --- a/lib/github_api/owner_repos.rb +++ b/lib/github_api/owner_repos.rb @@ -56,12 +56,14 @@ module GithubApi GRAPHQL def self.find(username) - response = GithubApi::Client.query(OwnerReposQuery, variables: { owner: username }) - if response.errors.any? - raise QueryExecutionError.new(response.errors[:data].join(", ")) - else - response.data.repository_owner.repositories.nodes.map(&:to_h) - end + #Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do + response = GithubApi::Client.query(OwnerReposQuery, variables: { owner: username }) + if response.errors.any? + raise QueryExecutionError.new(response.errors[:data].join(", ")) + else + response.data.repository_owner.repositories.nodes.map(&:to_h) + end + #end end end end diff --git a/lib/github_api/security_advisory.rb b/lib/github_api/security_advisory.rb index 011dde0..23496a5 100644 --- a/lib/github_api/security_advisory.rb +++ b/lib/github_api/security_advisory.rb @@ -45,12 +45,14 @@ class SecurityAdvisory GRAPHQL def self.find(ghsa_id) - response = GithubApi::Client.query(SecurityAdvisoryQuery, variables: { ghsa_id: ghsa_id }) - if response.errors.any? - raise QueryExecutionError.new(response.errors[:data].join(", ")) - else - response.data.security_advisory - end + #Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do + response = GithubApi::Client.query(SecurityAdvisoryQuery, variables: { ghsa_id: ghsa_id }) + if response.errors.any? + raise QueryExecutionError.new(response.errors[:data].join(", ")) + else + response.data.security_advisory + end + #end end end end diff --git a/lib/github_api/user.rb b/lib/github_api/user.rb index cdbdc22..1593bd6 100644 --- a/lib/github_api/user.rb +++ b/lib/github_api/user.rb @@ -16,12 +16,14 @@ class User GRAPHQL def self.find(username) + #Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do response = GithubApi::Client.query(UserProfileQuery, variables: { username: username }) if response.errors.any? raise QueryExecutionError.new(response.errors[:data].join(", ")) else response.data.user end + #end end end end diff --git a/lib/importers/github_user_importer.rb b/lib/importers/github_user_importer.rb index 51f1dfe..5a1d3ad 100644 --- a/lib/importers/github_user_importer.rb +++ b/lib/importers/github_user_importer.rb @@ -10,10 +10,12 @@ class GithubUserImporter def username_hashes usernames.map do |username| - username_response = GithubApi::User.find(username) - username_repos = GithubApi::OwnerRepos.find(username) - repos_hash = { 'repositories' => username_repos } - username_response.to_h.merge(repos_hash) + Retryable.retryable(tries: 3, on: QueryExecutionError, sleep: lambda { |n| 4**n } ) do + username_response = GithubApi::User.find(username) + username_repos = GithubApi::OwnerRepos.find(username) + repos_hash = { 'repositories' => username_repos } + username_response.to_h.merge(repos_hash) + end end end