Class: RServiceBus::CronManager
- Inherits:
-
Object
- Object
- RServiceBus::CronManager
- Defined in:
- lib/rservicebus/CronManager.rb
Instance Method Summary collapse
- #addCron(name, cron_string) ⇒ Object
- #getMatchingMsgNames(name) ⇒ Object
-
#initialize(host, msgNames = Array.new) ⇒ CronManager
constructor
A new instance of CronManager.
- #Run ⇒ Object
Constructor Details
#initialize(host, msgNames = Array.new) ⇒ CronManager
Returns a new instance of CronManager.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rservicebus/CronManager.rb', line 54 def initialize( host, msgNames=Array.new ) @Bus = host @msgNames = msgNames RServiceBus.rlog 'Load Cron' @list = Array.new ENV.each do |k,v| if k.start_with?('RSBCRON_') then self.addCron( k.sub( 'RSBCRON_', ''), v ) elsif k.start_with?('RSBCRON') then v.split(';').each do |v| parts = v.split( ' ', 6 ) self.addCron( parts.pop, parts.join(' ') ) end end end end |
Instance Method Details
#addCron(name, cron_string) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rservicebus/CronManager.rb', line 40 def addCron( name, cron_string ) self.getMatchingMsgNames( name ).each do |n| hash = Hash.new hash['name'] = n hash['last'] = Time.now hash['v'] = cron_string hash['cron'] = CronParser.new(cron_string) hash['next'] = hash['cron'].next(Time.now) @list << hash @Bus.log( "Cron set for, #{n}, #{cron_string}, next run, #{hash['next']}" ) end end |
#getMatchingMsgNames(name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rservicebus/CronManager.rb', line 26 def getMatchingMsgNames( name ) list = Array.new @msgNames.each do |n| if Globber.new( name ) =~ n then list << n end end if list.length == 0 then raise NoMatchingMsgForCron.new( name ) end return list end |
#Run ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rservicebus/CronManager.rb', line 74 def Run now = Time.now @list.each_with_index do |v,idx| if now > v['next'] then RServiceBus.rlog "CronManager.Send, #{v['name']}" @Bus.Send( RServiceBus.createAnonymousClass( v['name'] ) ) @list[idx]['next'] = v['cron'].next(now) end end end |