Class: DerivedImages::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/derived_images/worker.rb

Overview

A Worker represents a thread in a thread pool that completes image creation tasks.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue, cache = Cache.new) ⇒ Worker

Returns a new instance of Worker.



6
7
8
9
# File 'lib/derived_images/worker.rb', line 6

def initialize(queue, cache = Cache.new)
  @queue = queue
  @cache = cache
end

Class Method Details

.start(thread_group, queue) ⇒ Object



18
19
20
21
# File 'lib/derived_images/worker.rb', line 18

def self.start(thread_group, queue)
  DerivedImages.config.logger.debug('Starting a new worker thread')
  thread_group.add(Thread.new { Worker.new(queue).run })
end

Instance Method Details

#runObject



11
12
13
14
15
16
# File 'lib/derived_images/worker.rb', line 11

def run
  until queue.closed? && queue.empty?
    entry = queue.pop
    process(entry) if entry
  end
end