Class: Flor::Ganger

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#unitObject (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.

Returns:

  • (Boolean)


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(message)

  @unit.return(message)
end

#shutdownObject



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, message)

  domain = message['exid'].split('-', 2).first
  #tname = message['tasker']
  tname = determine_tasker_name(executor, message)

  tconf =
    ( ! message['routed'] &&
     (@unit.loader.tasker(domain, 'ganger', message) ||
      @unit.loader.tasker(domain, 'tasker', message))) ||
    @unit.loader.tasker(domain, tname, message)

  fail ArgumentError.new(
    "tasker #{tname.inspect} not found"
  ) unless tconf

  if tconf.is_a?(Array)

    points = [ nil, message['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)

  message['tconf'] = tconf unless tconf['include_tconf'] == false

  message['vars'] = gather_vars(executor, tconf, message)

  m = Flor.dup_message(message)
    #
    # 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