Class: Gitlab::GithubImport::PageCounter
- Inherits:
-
Object
- Object
- Gitlab::GithubImport::PageCounter
- Defined in:
- lib/gitlab/github_import/page_counter.rb
Overview
PageCounter 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 page number.
'%{import_type}/page-counter/%{object}/%{collection}'
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Instance Method Summary collapse
-
#current ⇒ Object
Returns the current value from the cache.
- #expire! ⇒ Object
-
#initialize(object, collection, import_type = 'github-importer') ⇒ PageCounter
constructor
A new instance of PageCounter.
-
#set(page) ⇒ Object
Sets the page number to the given value.
Constructor Details
#initialize(object, collection, import_type = 'github-importer') ⇒ PageCounter
Returns a new instance of PageCounter.
14 15 16 |
# File 'lib/gitlab/github_import/page_counter.rb', line 14 def initialize(object, collection, import_type = 'github-importer') @cache_key = CACHE_KEY % { import_type: import_type, object: object.id, collection: collection } end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
9 10 11 |
# File 'lib/gitlab/github_import/page_counter.rb', line 9 def cache_key @cache_key end |
Instance Method Details
#current ⇒ Object
Returns the current value from the cache.
26 27 28 |
# File 'lib/gitlab/github_import/page_counter.rb', line 26 def current Gitlab::Cache::Import::Caching.read_integer(cache_key) || 1 end |
#expire! ⇒ Object
30 31 32 |
# File 'lib/gitlab/github_import/page_counter.rb', line 30 def expire! Gitlab::Cache::Import::Caching.expire(cache_key, 0) end |
#set(page) ⇒ Object
Sets the page number to the given value.
Returns true if the page number was overwritten, false otherwise.
21 22 23 |
# File 'lib/gitlab/github_import/page_counter.rb', line 21 def set(page) Gitlab::Cache::Import::Caching.write_if_greater(cache_key, page) end |