class Flickrage::Worker::Base

Constants

MAX_ASK_ERRORS

Attributes

opts[RW]
service[RW]
spin[RW]

Public Class Methods

new(opts = {}, service = nil) click to toggle source
# File lib/flickrage/worker/base.rb, line 18
def initialize(opts = {}, service = nil)
  @service = service
  @opts = default_opts.merge(opts)
  @spin = nil
  @opts[:ask_error_counter] = 0
end

Public Instance Methods

call() click to toggle source
# File lib/flickrage/worker/base.rb, line 25
def call; end

Private Instance Methods

clean_thread_pool() click to toggle source
# File lib/flickrage/worker/base.rb, line 60
def clean_thread_pool
  return unless thread_pool
  thread_pool.kill
  Flickrage.config.pool = nil
end
default_opts() click to toggle source
# File lib/flickrage/worker/base.rb, line 29
def default_opts
  {}
end
increment_error_counter(error, value) { || ... } click to toggle source

Output helpers

# File lib/flickrage/worker/base.rb, line 37
def increment_error_counter(error, value)
  @opts[:ask_error_counter] += 1

  return unless opts[:ask_error_counter] >= MAX_ASK_ERRORS
  return yield if block_given?
  raise error, value
rescue SystemCallError => e
  logger.error(e.message)
  raise error, value
end
reset_error_counter() click to toggle source
# File lib/flickrage/worker/base.rb, line 48
def reset_error_counter
  @opts[:ask_error_counter] = 0
end
thread_pool() click to toggle source

Thread pool access

# File lib/flickrage/worker/base.rb, line 56
def thread_pool
  Flickrage.config.pool ||= Concurrent::FixedThreadPool.new(Flickrage.config.pool_size)
end
update_spin(spin, tags) click to toggle source

Update spin Due lots of changes in the spinner, keeping wrapper here.

# File lib/flickrage/worker/base.rb, line 71
def update_spin(spin, tags)
  spin.clear_line
  spin.update(tags)
  spin.spin
end