Class: Workling::Invokers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/workling/invokers/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routing, client_class) ⇒ Base

call up with super in the subclass constructor.



22
23
24
25
26
27
28
# File 'lib/workling/invokers/base.rb', line 22

def initialize(routing, client_class)
  @routing = routing
  @client_class = client_class
  @sleep_time = Workling.config[:sleep_time] || 2
  @reset_time = Workling.config[:reset_time] || 30
  @@mutex ||= Mutex.new
end

Instance Attribute Details

#reset_timeObject

Returns the value of attribute reset_time.



17
18
19
# File 'lib/workling/invokers/base.rb', line 17

def reset_time
  @reset_time
end

#sleep_timeObject

Returns the value of attribute sleep_time.



17
18
19
# File 'lib/workling/invokers/base.rb', line 17

def sleep_time
  @sleep_time
end

Instance Method Details

#listenObject

Starts main Invoker Loop. The invoker runs until stop() is called.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/workling/invokers/base.rb', line 33

def listen
  raise NotImplementedError.new("Implement listen() in your Invoker. ")
end

#loggerObject

returns the Workling::Base.logger



58
# File 'lib/workling/invokers/base.rb', line 58

def logger; Workling::Base.logger; end

#run(type, args) ⇒ Object

Runs the worker method, given

type: the worker route
args: the arguments to be passed into the worker method.


51
52
53
54
55
# File 'lib/workling/invokers/base.rb', line 51

def run(type, args)
  worker = @routing[type]
  method = @routing.method_name(type)
  worker.dispatch_to_worker_method(method, args)
end

#stopObject

Gracefully stops the Invoker. The currently executing Jobs should be allowed

to finish.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/workling/invokers/base.rb', line 41

def stop
  raise NotImplementedError.new("Implement stop() in your Invoker. ")
end