Class: Tobox::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, configuration) ⇒ Worker

Returns a new instance of Worker.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tobox/worker.rb', line 7

def initialize(label, configuration)
  @label = label
  @wait_for_events_delay = configuration[:wait_for_events_delay]
  @handlers = configuration.handlers || {}
  @fetcher = configuration.fetcher_class.new(label, configuration)
  @finished = false

  return unless (message_to_arguments = configuration.arguments_handler)

  define_singleton_method(:message_to_arguments, &message_to_arguments)
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/tobox/worker.rb', line 5

def label
  @label
end

Instance Method Details

#finish!Object



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

def finish!
  @finished = true
end

#finished?Boolean

Returns:

  • (Boolean)


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

def finished?
  @finished
end

#workObject



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

def work
  do_work until @finished
end