Class: Symphony::Metronome::Scheduler

Inherits:
Object
  • Object
show all
Extended by:
Configurability, Loggability
Includes:
SignalHandling
Defined in:
lib/symphony/metronome/scheduler.rb

Overview

Manage the delta queue of events and associated actions.

Constant Summary collapse

SIGNALS =

Signals the daemon responds to.

[ :HUP, :INT, :TERM ]
CONFIG_DEFAULTS =
{
	:listen => true
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Scheduler

:nodoc:



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
# File 'lib/symphony/metronome/scheduler.rb', line 49

def initialize( block ) #:nodoc:

	# Start the queue subscriber for schedule changes.
	#
	if self.class.listen
		Symphony::Metronome::ScheduledEvent.db.disconnect
		@child = fork do
			$0 = 'Metronome (listener)'
			Symphony::Metronome::ScheduleTask.run
		end
		Process.setpgid( @child, 0 )
	end

	# Signal handling for the master (this) process.
	#
	self.set_up_signal_handling
	self.set_signal_traps( *SIGNALS )

	@queue = Symphony::Metronome::ScheduledEvent.load
	@proc  = block

	# Enter the main loop.
	self.start

rescue => err
	self.log.error "%p while running: %s" % [ err.class, err.message ]
	self.log.debug "  " + err.backtrace.join( "\n  " )
	Process.kill( 'TERM', @child ) if self.class.listen
end

Class Attribute Details

.listenObject (readonly)

Should Metronome register and schedule events via AMQP? If false, you’ll need a separate way to add event actions to the database, and manually HUP the daemon.



28
29
30
# File 'lib/symphony/metronome/scheduler.rb', line 28

def listen
  @listen
end

Instance Attribute Details

#queueObject (readonly)

The sorted set of ScheduledEvent objects.



81
82
83
# File 'lib/symphony/metronome/scheduler.rb', line 81

def queue
  @queue
end

Class Method Details

.configure(config = nil) ⇒ Object

Configurability API



33
34
35
36
# File 'lib/symphony/metronome/scheduler.rb', line 33

def self::configure( config=nil )
	config = self.defaults.merge( config || {} )
	@listen = config.delete( :listen )
end

.run(&block) ⇒ Object

Create and start an instanced daemon.



41
42
43
# File 'lib/symphony/metronome/scheduler.rb', line 41

def self::run( &block )
	return new( block )
end