lucid_works 0.6.12 → 0.6.13
Sign up to get free protection for your applications and to get access to all the features.
@@ -112,5 +112,13 @@ module LucidWorks
|
|
112
112
|
def t_type
|
113
113
|
I18n.t(type, :scope => 'activemodel.models.lucid_works.datasource.type')
|
114
114
|
end
|
115
|
+
|
116
|
+
def progress
|
117
|
+
return nil if status.stopped?
|
118
|
+
return nil unless histories.size > 0
|
119
|
+
percent_done = status.elapsed_time.to_f / histories.last.duration
|
120
|
+
percent_done = nil if percent_done > 1.0
|
121
|
+
percent_done
|
122
|
+
end
|
115
123
|
end
|
116
124
|
end
|
data/lib/lucid_works/version.rb
CHANGED
@@ -296,15 +296,50 @@ describe LucidWorks::Datasource do
|
|
296
296
|
end
|
297
297
|
|
298
298
|
describe "#progress" do
|
299
|
+
before do
|
300
|
+
@datasource = LucidWorks::Datasource.new(
|
301
|
+
:collection => @collection,
|
302
|
+
:crawler => LucidWorks::Datasource::CRAWLERS['file'],
|
303
|
+
:type => 'file',
|
304
|
+
:name => "datasource we are going to get progress of",
|
305
|
+
:path => "/fake_ds_to_test_progress",
|
306
|
+
:crawl_depth => 2
|
307
|
+
)
|
308
|
+
@datasource.should be_valid
|
309
|
+
end
|
310
|
+
|
299
311
|
context "when the datasource has no prior history" do
|
300
|
-
it "should return nil"
|
312
|
+
it "should return nil" do
|
313
|
+
@datasource.progress.should be_nil
|
314
|
+
end
|
301
315
|
end
|
316
|
+
|
302
317
|
context "when the datasource has history" do
|
318
|
+
before do
|
319
|
+
mock_history = double("history", :duration => 4000)
|
320
|
+
@datasource.stub(:histories) { [mock_history] }
|
321
|
+
end
|
322
|
+
|
303
323
|
context "and the most last crawl duration was longer then our current crawl duration" do
|
304
|
-
|
324
|
+
before do
|
325
|
+
mock_status = double('status', :stopped? => false, :elapsed_time => 1000)
|
326
|
+
@datasource.stub(:status) { mock_status }
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should return the fraction completed (between 0.0 and 1.0)" do
|
330
|
+
@datasource.progress.should == 0.25
|
331
|
+
end
|
305
332
|
end
|
306
|
-
|
307
|
-
|
333
|
+
|
334
|
+
context "and the most recent crawl duration was shorter than our current duration" do
|
335
|
+
before do
|
336
|
+
mock_status = double('status', :stopped? => false, :elapsed_time => 5000)
|
337
|
+
@datasource.stub(:status) { mock_status }
|
338
|
+
end
|
339
|
+
|
340
|
+
it "should return nil" do
|
341
|
+
@datasource.progress.should be_nil
|
342
|
+
end
|
308
343
|
end
|
309
344
|
end
|
310
345
|
end
|