Class: Flor::Ganger
- Inherits:
-
Object
- Object
- Flor::Ganger
- Defined in:
- lib/flor/unit/ganger.rb
Overview
ganger | ˈɡaNGər | \ noun British \ the foreman of a gang of laborers.
The ganger receives the tasks from the flor executor, decides what tasker will be invoked and hands it the task.
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
RESERVED_NAMES = %w[ tag ].
Instance Method Summary collapse
-
#has_tasker?(exid, name) ⇒ Boolean
Used by flor when it looks up for a variable and finds nothing.
-
#initialize(unit) ⇒ Ganger
constructor
A new instance of Ganger.
-
#return(message) ⇒ Object
Called by the tasker implementations when they’re done with a task and want to hand it back to flor.
- #shutdown ⇒ Object
-
#task(executor, message) ⇒ Object
Called by Flor::Scheduler.
Constructor Details
#initialize(unit) ⇒ Ganger
Returns a new instance of Ganger.
18 19 20 21 |
# File 'lib/flor/unit/ganger.rb', line 18 def initialize(unit) @unit = unit end |
Instance Attribute Details
#unit ⇒ Object (readonly)
RESERVED_NAMES = %w[ tag ]
16 17 18 |
# File 'lib/flor/unit/ganger.rb', line 16 def unit @unit end |
Instance Method Details
#has_tasker?(exid, name) ⇒ Boolean
Used by flor when it looks up for a variable and finds nothing. The last step is to ask the ganger if it knows about a tasker under the given (domain and) name.
If it returns true, flor knows there is a tasker under that name.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/flor/unit/ganger.rb', line 32 def has_tasker?(exid, name) #return false if RESERVED_NAMES.include?(name) d = Flor.domain(exid) !! ( @unit.loader.tasker(d, 'ganger') || @unit.loader.tasker(d, 'tasker') || @unit.loader.tasker(d, name)) end |
#return(message) ⇒ Object
Called by the tasker implementations when they’re done with a task and want to hand it back to flor. It might be a failure message.
95 96 97 98 |
# File 'lib/flor/unit/ganger.rb', line 95 def return() @unit.return() end |
#shutdown ⇒ Object
23 24 |
# File 'lib/flor/unit/ganger.rb', line 23 def shutdown end |
#task(executor, message) ⇒ Object
Called by Flor::Scheduler. The ganger then has to hand the task (the message) to the proper tasker.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/flor/unit/ganger.rb', line 47 def task(executor, ) domain = ['exid'].split('-', 2).first #tname = message['tasker'] tname = determine_tasker_name(executor, ) tconf = ( ! ['routed'] && (@unit.loader.tasker(domain, 'ganger', ) || @unit.loader.tasker(domain, 'tasker', ))) || @unit.loader.tasker(domain, tname, ) fail ArgumentError.new( "tasker #{tname.inspect} not found" ) unless tconf if tconf.is_a?(Array) points = [ nil, ['point'] ] points << 'detask' if points.include?('cancel') points << 'task' if points.include?('return') tconf = tconf.find { |h| points.include?(h['point']) } end fail ArgumentError.new( "tconf #{tconf.inspect} not a hash" ) unless tconf.is_a?(Hash) ['tconf'] = tconf unless tconf['include_tconf'] == false ['vars'] = gather_vars(executor, tconf, ) m = Flor.() # # the tasker gets a copy of the message (and it can play with it # to its heart content), meanwhile the message is handed to the # "post" notifiers. @unit.caller.call(self, tconf, m) # # might return a re-routing message, # especially if it's a domain tasker end |