Class: Threaded::Worker

Inherits:
Object
  • Object
show all
Includes:
Timeout
Defined in:
lib/threaded/worker.rb

Constant Summary collapse

DEFAULT_TIMEOUT =

seconds, 1 minute

60
POISON =
"poison"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Timeout

#timeout

Constructor Details

#initialize(queue, options = {}) ⇒ Worker

Returns a new instance of Worker.



8
9
10
11
12
13
# File 'lib/threaded/worker.rb', line 8

def initialize(queue, options = {})
  @queue   = queue
  @timeout = options[:timeout] || DEFAULT_TIMEOUT
  @logger  = options[:logger]  || Threaded.logger
  @thread  = create_thread
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#threadObject (readonly)

Returns the value of attribute thread.



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

def thread
  @thread
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/threaded/worker.rb', line 23

def alive?
  thread.alive?
end

#joinObject



27
28
29
# File 'lib/threaded/worker.rb', line 27

def join
  thread.join
end

#poisonObject



15
16
17
# File 'lib/threaded/worker.rb', line 15

def poison
  @queue.enq(POISON)
end

#startObject



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

def start
  puts "start is deprecated, thread is started when worker created"
end