Class: Gitlab::Import::PageKeyset

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/import/page_keyset.rb

Overview

PageKeyset can be used to keep track of the last imported page of a collection, allowing workers to resume where they left off in the event of an error.

Constant Summary collapse

CACHE_KEY =

The base cache key to use for storing the last key.

'%{import_type}/page-keyset/%{object}/%{collection}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, collection, import_type) ⇒ PageKeyset

Returns a new instance of PageKeyset.



14
15
16
# File 'lib/gitlab/import/page_keyset.rb', line 14

def initialize(object, collection, import_type)
  @cache_key = format(CACHE_KEY, import_type: import_type, object: object.id, collection: collection)
end

Instance Attribute Details

#cache_keyObject (readonly)

Returns the value of attribute cache_key.



9
10
11
# File 'lib/gitlab/import/page_keyset.rb', line 9

def cache_key
  @cache_key
end

Instance Method Details

#currentString

Get the current value from the cache

Returns:

  • (String)


29
30
31
# File 'lib/gitlab/import/page_keyset.rb', line 29

def current
  Gitlab::Cache::Import::Caching.read(cache_key)
end

#expire!Boolean

Expire the key

Returns:

  • (Boolean)


36
37
38
# File 'lib/gitlab/import/page_keyset.rb', line 36

def expire!
  Gitlab::Cache::Import::Caching.expire(cache_key, 0)
end

#set(value) ⇒ String

Set the key to the given value.

Parameters:

  • value (String)

Returns:

  • (String)


22
23
24
# File 'lib/gitlab/import/page_keyset.rb', line 22

def set(value)
  Gitlab::Cache::Import::Caching.write(cache_key, value)
end