rservicebus 0.1.35 → 0.1.36
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rservicebus/CronManager.rb +75 -42
- data/lib/rservicebus/HandlerManager.rb +17 -11
- data/lib/rservicebus/Host.rb +8 -8
- metadata +11 -11
@@ -2,55 +2,88 @@ module RServiceBus
|
|
2
2
|
|
3
3
|
require 'parse-cron'
|
4
4
|
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
hash['cron'] = CronParser.new(cron_string)
|
32
|
-
hash['next'] = hash['cron'].next(Time.now)
|
33
|
-
@list << hash
|
34
|
-
@Bus.log( "Cron set for, #{hash['name']}, #{v}" )
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
5
|
+
class Globber
|
6
|
+
def self.parse_to_regex(str)
|
7
|
+
escaped = Regexp.escape(str).gsub('\*','.*?')
|
8
|
+
Regexp.new "^#{escaped}$", Regexp::IGNORECASE
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(str)
|
12
|
+
@regex = self.class.parse_to_regex str
|
13
|
+
end
|
14
|
+
|
15
|
+
def =~(str)
|
16
|
+
!!(str =~ @regex)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class NoMatchingMsgForCron<StandardError
|
21
|
+
end
|
22
|
+
|
23
|
+
class CronManager
|
24
|
+
|
25
|
+
|
26
|
+
def getMatchingMsgNames( name )
|
27
|
+
list = Array.new
|
28
|
+
@msgNames.each do |n|
|
29
|
+
if Globber.new( name ) =~ n then
|
30
|
+
list << n
|
38
31
|
end
|
39
32
|
end
|
33
|
+
if list.length == 0 then
|
34
|
+
raise NoMatchingMsgForCron.new( name )
|
35
|
+
end
|
36
|
+
|
37
|
+
return list
|
38
|
+
end
|
39
|
+
|
40
|
+
def addCron( name, cron_string )
|
41
|
+
|
42
|
+
self.getMatchingMsgNames( name ).each do |n|
|
43
|
+
hash = Hash.new
|
44
|
+
hash['name'] = n
|
45
|
+
hash['last'] = Time.now
|
46
|
+
hash['v'] = cron_string
|
47
|
+
hash['cron'] = CronParser.new(cron_string)
|
48
|
+
hash['next'] = hash['cron'].next(Time.now)
|
49
|
+
@list << hash
|
50
|
+
@Bus.log( "Cron set for, #{name}, #{cron_string}" )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def initialize( host, msgNames=Array.new )
|
55
|
+
@Bus = host
|
56
|
+
@msgNames = msgNames
|
40
57
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
58
|
+
@Bus.log "Load Cron", true
|
59
|
+
@list = Array.new
|
60
|
+
ENV.each do |k,v|
|
61
|
+
if k.start_with?( "RSBCRON_" ) then
|
62
|
+
self.addCron( k.sub( "RSBCRON_", "" ), v )
|
63
|
+
elsif k.start_with?( "RSBCRON" ) then
|
64
|
+
v.split( ";" ).each do |v|
|
65
|
+
parts = v.split( " ", 6 )
|
66
|
+
|
67
|
+
self.addCron( parts.pop, parts.join( " " ) )
|
48
68
|
end
|
49
|
-
return v
|
50
69
|
end
|
70
|
+
|
51
71
|
end
|
52
|
-
|
53
72
|
end
|
54
73
|
|
74
|
+
def Run
|
75
|
+
now = Time.now
|
76
|
+
@list.map! do |v|
|
77
|
+
if now > v['next'] then
|
78
|
+
@Bus.log "CronManager.Send, #{v['name']}", true
|
79
|
+
@Bus.Send( RServiceBus.createAnonymousClass( v['name'] ) )
|
80
|
+
v['next'] = v['cron'].next(now)
|
81
|
+
end
|
82
|
+
return v
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
55
88
|
end
|
56
89
|
|
@@ -5,7 +5,7 @@ module RServiceBus
|
|
5
5
|
# handlernames, and
|
6
6
|
# loading handlers
|
7
7
|
class HandlerManager
|
8
|
-
|
8
|
+
|
9
9
|
# Constructor
|
10
10
|
#
|
11
11
|
# @param [RServiceBus::Host] host instance
|
@@ -18,8 +18,8 @@ module RServiceBus
|
|
18
18
|
@handlerList = Hash.new
|
19
19
|
@resourceListByHandlerName = Hash.new
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
|
23
23
|
# setBusAttributeIfRequested
|
24
24
|
#
|
25
25
|
# @param [RServiceBus::Handler] handler
|
@@ -31,7 +31,7 @@ module RServiceBus
|
|
31
31
|
|
32
32
|
return self
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# setStateAttributeIfRequested
|
36
36
|
#
|
37
37
|
# @param [RServiceBus::Handler] handler
|
@@ -71,7 +71,7 @@ module RServiceBus
|
|
71
71
|
def addHandler( msgName, handler )
|
72
72
|
@handlerList[msgName] = Array.new if @handlerList[msgName].nil?
|
73
73
|
return unless @handlerList[msgName].index{ |x| x.class.name == handler.class.name }.nil?
|
74
|
-
|
74
|
+
|
75
75
|
@handlerList[msgName] << handler
|
76
76
|
self.setBusAttributeIfRequested( handler )
|
77
77
|
self.checkIfStateAttributeRequested( handler )
|
@@ -110,7 +110,7 @@ module RServiceBus
|
|
110
110
|
def setResourcesForHandlersNeededToProcessMsg( msgName )
|
111
111
|
@handlerList[msgName].each do |handler|
|
112
112
|
self.setStateAttributeIfRequested( handler )
|
113
|
-
|
113
|
+
|
114
114
|
next if @resourceListByHandlerName[handler.class.name].nil?
|
115
115
|
@resourceListByHandlerName[handler.class.name].each do |k|
|
116
116
|
handler.instance_variable_set( "@#{k}", @appResources[k].getResource() )
|
@@ -122,7 +122,7 @@ module RServiceBus
|
|
122
122
|
|
123
123
|
def getHandlerListForMsg( msgName )
|
124
124
|
raise NoHandlerFound.new( msgName ) if @handlerList[msgName].nil?
|
125
|
-
|
125
|
+
|
126
126
|
@stateManager.Begin
|
127
127
|
list = self.getListOfResourcesNeededToProcessMsg( msgName )
|
128
128
|
list.each do |resourceName|
|
@@ -141,10 +141,10 @@ module RServiceBus
|
|
141
141
|
@host.log "HandlerManager.commitResourcesUsedToProcessMsg, #{msgName}", true
|
142
142
|
list = self.getListOfResourcesNeededToProcessMsg( msgName )
|
143
143
|
list.each do |resourceName|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
r = @appResources[resourceName]
|
145
|
+
@host.log "Commit resource, #{r.class.name}", true
|
146
|
+
r.Commit
|
147
|
+
r.finished
|
148
148
|
end
|
149
149
|
@stateManager.Commit
|
150
150
|
end
|
@@ -181,5 +181,11 @@ module RServiceBus
|
|
181
181
|
|
182
182
|
return list
|
183
183
|
end
|
184
|
+
|
185
|
+
def getListOfMsgNames
|
186
|
+
return @handlerList.keys
|
187
|
+
end
|
188
|
+
|
189
|
+
|
184
190
|
end
|
185
191
|
end
|
data/lib/rservicebus/Host.rb
CHANGED
@@ -58,13 +58,6 @@ module RServiceBus
|
|
58
58
|
return self;
|
59
59
|
end
|
60
60
|
|
61
|
-
#Thin veneer for Configuring Cron
|
62
|
-
#
|
63
|
-
def configureCronManager
|
64
|
-
@cronManager = CronManager.new( self )
|
65
|
-
return self;
|
66
|
-
end
|
67
|
-
|
68
61
|
#Thin veneer for Configuring Cron
|
69
62
|
#
|
70
63
|
def configureCircuitBreaker
|
@@ -112,6 +105,13 @@ module RServiceBus
|
|
112
105
|
return self
|
113
106
|
end
|
114
107
|
|
108
|
+
#Thin veneer for Configuring Cron
|
109
|
+
#
|
110
|
+
def configureCronManager
|
111
|
+
@cronManager = CronManager.new( self, @handlerManager.getListOfMsgNames )
|
112
|
+
return self;
|
113
|
+
end
|
114
|
+
|
115
115
|
#Load Contracts
|
116
116
|
#
|
117
117
|
def loadContracts()
|
@@ -171,10 +171,10 @@ module RServiceBus
|
|
171
171
|
.loadLibs()
|
172
172
|
.configureAppResource()
|
173
173
|
.configureStateManager()
|
174
|
-
.configureCronManager()
|
175
174
|
.configureCircuitBreaker()
|
176
175
|
.configureMonitors()
|
177
176
|
.loadHandlers()
|
177
|
+
.configureCronManager()
|
178
178
|
.connectToMq()
|
179
179
|
.configureSubscriptions()
|
180
180
|
.sendSubscriptions()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rservicebus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.36
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2013-10-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: uuidtools
|
16
|
-
requirement: &
|
16
|
+
requirement: &70240671828320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70240671828320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70240671827840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70240671827840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: beanstalk-client
|
38
|
-
requirement: &
|
38
|
+
requirement: &70240671827400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70240671827400
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: fluiddb
|
49
|
-
requirement: &
|
49
|
+
requirement: &70240671826940 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70240671826940
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: parse-cron
|
60
|
-
requirement: &
|
60
|
+
requirement: &70240671826460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70240671826460
|
69
69
|
description: A Ruby interpretation of NServiceBus
|
70
70
|
email: guy@guyirvine.com
|
71
71
|
executables:
|