Class: Gitlab::GithubGistsImport::Importer::GistsImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_gists_import/importer/gists_importer.rb

Defined Under Namespace

Classes: RESULT_CONTEXT

Constant Summary collapse

ALREADY_IMPORTED_CACHE_KEY =
'github-gists-importer/already-imported/%{user}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, token) ⇒ GistsImporter

Returns a new instance of GistsImporter.



12
13
14
15
16
# File 'lib/gitlab/github_gists_import/importer/gists_importer.rb', line 12

def initialize(user, token)
  @user = user
  @client = Gitlab::GithubImport::Client.new(token, parallel: true)
  @already_imported_cache_key = format(ALREADY_IMPORTED_CACHE_KEY, user: user.id)
end

Instance Attribute Details

#already_imported_cache_keyObject (readonly)

Returns the value of attribute already_imported_cache_key.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gists_importer.rb', line 7

def already_imported_cache_key
  @already_imported_cache_key
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gists_importer.rb', line 7

def client
  @client
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/gitlab/github_gists_import/importer/gists_importer.rb', line 7

def user
  @user
end

Instance Method Details

#executeObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/github_gists_import/importer/gists_importer.rb', line 18

def execute
  waiter = spread_parallel_import

  expire_already_imported_cache!

  RESULT_CONTEXT.new(success?: true, waiter: waiter)
rescue Gitlab::GithubImport::RateLimitError => e
  RESULT_CONTEXT.new(success?: false, error: e, next_attempt_in: client.rate_limit_resets_in)
rescue StandardError => e
  RESULT_CONTEXT.new(success?: false, error: e)
end