Class: LanGrove::Adaptor::QueryAdaptor
Instance Attribute Summary
Attributes inherited from Base
#logger
Instance Method Summary
collapse
#path, #validate_tls_options
Methods inherited from Base
#listen, #validate_config_adaptor
Methods inherited from Base
#config_exception, #type
Constructor Details
#initialize(root, config, deamon_name) ⇒ QueryAdaptor
Returns a new instance of QueryAdaptor.
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 105
def initialize( root, config, deamon_name )
super
@run_interval = @config[:run_interval]
@run_once = false
@run_once = @config[:run_once]
@done_once = false
@run_immediately = @config[:run_immediately]
@run_immediately = true if @run_immediately.nil?
config_exception(
"#{self.class} requires subconfig with :run_interval:"
) if (
@run_interval.nil? or
not @run_interval.is_a?( Integer )
)
@query = @config[:query]
config_exception(
"#{self.class} requires :query: subconfig"
) if @query.nil?
validate_config
connect
end
|
Instance Method Details
#connect ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 43
def connect
end
|
#connector(params, &block) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 171
def connector( params, &block )
if params[:handler][:class] == LanGrove::Handler::Socket
params[:handler][:class] = LanGrove::Handler::Base
end
if @run_immediately
do_query( params, &block )
end
EM.add_periodic_timer( @run_interval ) do
do_query( params, &block )
end
end
|
#do_query(params, &block) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 200
def do_query( params, &block )
if running?
@logger.info "#{self.class} already running query"
return
end
if @run_once and @done_once
@logger.warn "#{self.class} set to :run_once:"
Process.kill( 'TERM', Process.pid )
return
end
operation = proc do
query do |record|
handler = params[:handler][:class].new
yield handler if block
@root.trigger( handler, :handler, :receive )
handler.receive( record )
@root.trigger( handler, :handler, :after_receive )
end
end
callback = proc do |result|
@done_once = true
end
EM.defer( operation, callback )
end
|
#query(&block) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 84
def query( &block )
raise LanGrove::PluginException.new(
"#{self.class}.query( ... ) - missing implementation."
)
end
|
#reload ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 23
def reload
end
|
#reload_adaptor ⇒ Object
78
79
80
81
82
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 78
def reload_adaptor
reload
end
|
#running? ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 53
def running?
false
end
|
#stop ⇒ Object
Used to periodically query a datasource, Yields rows as handlers into the daemon’s event pipeline
13
14
15
16
17
18
19
20
21
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 13
def stop
end
|
#stop_adaptor ⇒ Object
72
73
74
75
76
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 72
def stop_adaptor
stop
end
|
#validate_config ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/langrove/adaptor/query_adaptor.rb', line 33
def validate_config
end
|