Module: Gitlab::GithubImport::ReschedulingMethods

Defined in:
app/workers/concerns/gitlab/github_import/rescheduling_methods.rb

Overview

Module that provides methods shared by the various workers used for importing GitHub projects.

Instance Method Summary collapse

Instance Method Details

#notify_waiter(key = nil) ⇒ Object


37
38
39
# File 'app/workers/concerns/gitlab/github_import/rescheduling_methods.rb', line 37

def notify_waiter(key = nil)
  JobWaiter.notify(key, jid) if key
end

#perform(project_id, hash, notify_key = nil) ⇒ Object

project_id - The ID of the GitLab project to import the note into. hash - A Hash containing the details of the GitHub object to imoprt. notify_key - The Redis key to notify upon completion, if any. rubocop: disable CodeReuse/ActiveRecord


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/workers/concerns/gitlab/github_import/rescheduling_methods.rb', line 12

def perform(project_id, hash, notify_key = nil)
  project = Project.find_by(id: project_id)

  return notify_waiter(notify_key) unless project

  client = GithubImport.new_client_for(project, parallel: true)

  if try_import(project, client, hash)
    notify_waiter(notify_key)
  else
    # In the event of hitting the rate limit we want to reschedule the job
    # so its retried after our rate limit has been reset.
    self.class
      .perform_in(client.rate_limit_resets_in, project.id, hash, notify_key)
  end
end

#try_import(*args) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


30
31
32
33
34
35
# File 'app/workers/concerns/gitlab/github_import/rescheduling_methods.rb', line 30

def try_import(*args)
  import(*args)
  true
rescue RateLimitError
  false
end