Class: ProcessWanker::Event

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

Overview

basic event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#serviceObject

Returns the value of attribute service.



32
33
34
# File 'lib/events.rb', line 32

def service
  @service
end

#service_nameObject

Returns the value of attribute service_name.



33
34
35
# File 'lib/events.rb', line 33

def service_name
  @service_name
end

#service_stateObject

Returns the value of attribute service_state.



35
36
37
# File 'lib/events.rb', line 35

def service_state
  @service_state
end

#service_statsObject

Returns the value of attribute service_stats.



34
35
36
# File 'lib/events.rb', line 34

def service_stats
  @service_stats
end

#timeObject

Returns the value of attribute time.



36
37
38
# File 'lib/events.rb', line 36

def time
  @time
end

#typeObject

Returns the value of attribute type.



31
32
33
# File 'lib/events.rb', line 31

def type
  @type
end

Class Method Details

.dispatch(type, service) ⇒ Object



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
# File 'lib/events.rb', line 44

def self.dispatch(type,service)
	
	Log::debug("dispatching event #{type} for service #{service.name}")
	
	e=Event.new()
	e.type=type
	e.service=service
	e.service_name=service.name
	e.service_stats={}
#			e.service_stats=service.stats
	e.service_state=service.current_state
	e.time=Time.now

	# build array of hooks, from innermost to outermost
	stop=false
	hooks_lists=service.config_node.find_attributes("hooks")
	hooks_lists.each do |hooks|
		hooks.each do |hook|
			
			next unless(hook.pattern == type)
			context=EventHookContext.new
			context.service=service
			context.event=e
			
			ProcessWanker::with_logged_rescue("hook for event #{e.type} #{e.service.name}") do
				context.instance_eval(&hook.block)
			end
			
			stop=context.should_stop_hooks
			if(stop)
				break
			end
		end
		break if(stop)
	end
	
end