Class: LanGrove::Handler::Deferred

Inherits:
Object
  • Object
show all
Includes:
LanGrove::Handler
Defined in:
lib/langrove/handler/deferred.rb

Constant Summary

Constants included from LanGrove::Handler

Default

Instance Attribute Summary

Attributes included from LanGrove::Handler

#capsule, #config, #key, #logger, #pending_capsule, #protocol, #scheduler, #server, #type

Instance Method Summary collapse

Methods included from LanGrove::Handler

#assign, #connect, #disconnect, #error, #event_filter, #receive, #reload, #reload_handler, #start, #start_handler, #stop, #stop_handler, #transform, #unique

Instance Method Details

#get_capsuleObject



38
39
40
41
42
43
44
45
46
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
91
92
93
94
95
96
97
98
99
# File 'lib/langrove/handler/deferred.rb', line 38

def get_capsule
  
  #
  # A call to action: get_capusle will have
  # been made by deferrer.defer_key
  #
  # Meaning that the payload is the key to collect
  # the corresponding persisted capsule
  # 
  @key = payload['args'][1]
  
  #
  # Ensure persistable behaviour is loaded.
  # 
  # This will fail the job, not bring the daemon down...
  # 
  unless server.respond_to?( :persistor )
    
    raise LanGrove::DaemonConfigException.new(
    
      "#{self.class}.get_capsule() requires the Persistable behaviour."
    
    )
    
  end
  
  @root.trigger( self, :handler, :receive )
  
  # 
  # Collect the capsule, 
  # 
  # Failure to fetch MUST raise,
  # Job must fail... (Could not collect)
  #
  server.persistor.fetch_handler( self )
  
  #
  # If :latest: is enabled, compare the collected 
  # capsule persisted_seq with the header in the
  # job payload,
  #
  
  self.receive( @capsule )
  
  @root.trigger( self, :handler, :after_receive )
  
  if @config.has_key?( :latest )

    enqueued = payload['args'][0]['sequence']
    persisted = capsule['persisted_seq']
    
    unless enqueued.nil? or persisted.nil?
      
       return enqueued == persisted
      
    end
    
  end
  
  return true
  
end

#load_capsuleObject

The deferror calls an :action to be prformed by the handler that performs the job.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/langrove/handler/deferred.rb', line 14

def load_capsule

  @logger.debug "#{self}.load_capsule()"
  
  #
  # A call to action: load_capsule will have
  # been made by deferrer.defer_capsule
  # 
  # Meaning that the payload is the capsule itself
  # and should be moved into position in the handler
  #
  
  @root.trigger( self, :handler, :receive )
  
  @capsule = payload['args'][1]
  
  self.receive( @capsule )
  
  @root.trigger( self, :handler, :after_receive )
  
  return true
  
end