Module: Hitnmiss::BackgroundRefreshRepository::InstanceMethods
- Defined in:
- lib/hitnmiss/background_refresh_repository.rb
Instance Method Summary collapse
- #background_refresh(*args, swallow_exceptions: []) ⇒ Object
- #initialize ⇒ Object
- #refresh(*args, swallow_exceptions: []) ⇒ Object
- #stale?(*args) ⇒ Boolean
Instance Method Details
#background_refresh(*args, swallow_exceptions: []) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/hitnmiss/background_refresh_repository.rb', line 50 def background_refresh(*args, swallow_exceptions: []) @refresh_thread = Thread.new(self, args) do |repository, args| while(true) do refresh(*args, swallow_exceptions: swallow_exceptions) sleep repository.class.refresh_interval end end @refresh_thread.abort_on_exception = true end |
#initialize ⇒ Object
25 26 27 28 29 |
# File 'lib/hitnmiss/background_refresh_repository.rb', line 25 def initialize if self.class.refresh_interval.nil? raise RefreshIntervalRequired, 'the refresh_interval must be set' end end |
#refresh(*args, swallow_exceptions: []) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hitnmiss/background_refresh_repository.rb', line 35 def refresh(*args, swallow_exceptions: []) if swallow_exceptions.empty? if stale?(*args) prime(*args) end else begin if stale?(*args) prime(*args) end rescue *swallow_exceptions end end end |
#stale?(*args) ⇒ Boolean
31 32 33 |
# File 'lib/hitnmiss/background_refresh_repository.rb', line 31 def stale?(*args) true end |