blacklight-spotlight 0.20.2 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/spotlight/reindex_monitor.js +2 -2
- data/app/models/spotlight/exhibit.rb +1 -1
- data/app/models/spotlight/reindex_progress.rb +32 -52
- data/app/models/spotlight/resource.rb +11 -0
- data/lib/spotlight/version.rb +1 -1
- data/spec/models/spotlight/reindex_progress_spec.rb +34 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f570da0859bafcdda5b278a6c091c078d3923a
|
4
|
+
data.tar.gz: f949ab89b4ae716b88a2b1637ed74ed661706193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c16e162aefe79ed7d01a1886c7636208cce5d82c5826e921a66ec0e440b41893588ff7c7eaf64bae4862fbbfd943deb20c9ad271074debfa8e4b93297c99bfb6
|
7
|
+
data.tar.gz: 5c603afe59cc54c39e476eed12ca820d183007968b68cd1c01c18466216c721f8460bcffad3114dc65de902f1f09f5af2d406134fe4ac8d3c839eae36b26d9b4
|
@@ -22,7 +22,7 @@ Spotlight.onLoad(function() {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
function success(data) {
|
25
|
-
if (data.
|
25
|
+
if (data.recently_in_progress) {
|
26
26
|
monitorPanel().show();
|
27
27
|
updateMonitorPanel(data);
|
28
28
|
} else {
|
@@ -33,7 +33,7 @@ Spotlight.onLoad(function() {
|
|
33
33
|
function fail() { monitorPanel().hide(); }
|
34
34
|
|
35
35
|
function updateMonitorPanel(data) {
|
36
|
-
panelStartDate().text(data.
|
36
|
+
panelStartDate().text(data.started_at);
|
37
37
|
panelCurrentDate().text(data.updated_at);
|
38
38
|
panelCompleted().text(data.completed);
|
39
39
|
updatePanelTotals(data);
|
@@ -4,23 +4,33 @@ module Spotlight
|
|
4
4
|
class ReindexProgress
|
5
5
|
def initialize(resource_list)
|
6
6
|
@resources = if resource_list.present?
|
7
|
-
resource_list
|
7
|
+
resource_list.order('updated_at')
|
8
8
|
else
|
9
|
-
|
9
|
+
Spotlight::Resource.none
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
any_waiting? || finished > Spotlight::Engine.config.reindex_progress_window.minutes.ago
|
13
|
+
def recently_in_progress?
|
14
|
+
any_waiting? || (!!finished_at && finished_at > Spotlight::Engine.config.reindex_progress_window.minutes.ago)
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
19
|
-
|
17
|
+
def started_at
|
18
|
+
return unless resources.present?
|
19
|
+
|
20
|
+
@started ||= resources.min_by(&:enqueued_at).enqueued_at
|
21
|
+
end
|
22
|
+
|
23
|
+
def updated_at
|
24
|
+
@updated ||= resources.maximum(:updated_at) || started_at
|
20
25
|
end
|
21
26
|
|
22
|
-
def finished
|
23
|
-
|
27
|
+
def finished?
|
28
|
+
completed_resources.present? && !any_waiting?
|
29
|
+
end
|
30
|
+
|
31
|
+
def finished_at
|
32
|
+
return unless finished?
|
33
|
+
@finished ||= completed_resources.max_by(&:last_indexed_finished).last_indexed_finished
|
24
34
|
end
|
25
35
|
|
26
36
|
def total
|
@@ -37,11 +47,12 @@ module Spotlight
|
|
37
47
|
|
38
48
|
def as_json(*)
|
39
49
|
{
|
40
|
-
|
41
|
-
|
50
|
+
recently_in_progress: recently_in_progress?,
|
51
|
+
started_at: localized_start_time,
|
52
|
+
finished_at: localized_finish_time,
|
53
|
+
updated_at: localized_updated_time,
|
42
54
|
total: total,
|
43
55
|
completed: completed,
|
44
|
-
updated_at: localized_finish_time,
|
45
56
|
errored: errored?
|
46
57
|
}
|
47
58
|
end
|
@@ -55,53 +66,22 @@ module Spotlight
|
|
55
66
|
end
|
56
67
|
|
57
68
|
def localized_start_time
|
58
|
-
return unless
|
59
|
-
I18n.l(
|
69
|
+
return unless started_at
|
70
|
+
I18n.l(started_at, format: :short)
|
60
71
|
end
|
61
72
|
|
62
73
|
def localized_finish_time
|
63
|
-
return unless
|
64
|
-
I18n.l(
|
65
|
-
end
|
66
|
-
|
67
|
-
def completed_resources
|
68
|
-
if resources.try(:completed).present?
|
69
|
-
resources.completed
|
70
|
-
else
|
71
|
-
null_resources
|
72
|
-
end
|
74
|
+
return unless finished_at
|
75
|
+
I18n.l(finished_at, format: :short)
|
73
76
|
end
|
74
77
|
|
75
|
-
def
|
76
|
-
|
78
|
+
def localized_updated_time
|
79
|
+
return unless updated_at
|
80
|
+
I18n.l(updated_at, format: :short)
|
77
81
|
end
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
class NullResource
|
82
|
-
def updated_at
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
|
86
|
-
def indexed_at
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
|
90
|
-
def last_indexed_estimate
|
91
|
-
0
|
92
|
-
end
|
93
|
-
|
94
|
-
def last_indexed_count
|
95
|
-
0
|
96
|
-
end
|
97
|
-
|
98
|
-
def waiting?
|
99
|
-
false
|
100
|
-
end
|
101
|
-
|
102
|
-
def errored?
|
103
|
-
false
|
104
|
-
end
|
83
|
+
def completed_resources
|
84
|
+
resources.completed
|
105
85
|
end
|
106
86
|
end
|
107
87
|
end
|
@@ -15,6 +15,7 @@ module Spotlight
|
|
15
15
|
belongs_to :exhibit
|
16
16
|
serialize :data, Hash
|
17
17
|
store :metadata, accessors: [
|
18
|
+
:enqueued_at,
|
18
19
|
:last_indexed_estimate,
|
19
20
|
:last_indexed_count,
|
20
21
|
:last_index_elapsed_time,
|
@@ -42,6 +43,16 @@ module Spotlight
|
|
42
43
|
Spotlight::ReindexJob.perform_later(self)
|
43
44
|
end
|
44
45
|
|
46
|
+
def waiting!
|
47
|
+
update(enqueued_at: Time.zone.now)
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def enqueued_at
|
52
|
+
value = super
|
53
|
+
Time.zone.parse(value) if value
|
54
|
+
end
|
55
|
+
|
45
56
|
def document_model
|
46
57
|
exhibit.blacklight_config.document_model if exhibit
|
47
58
|
end
|
data/lib/spotlight/version.rb
CHANGED
@@ -1,82 +1,96 @@
|
|
1
1
|
describe Spotlight::ReindexProgress, type: :model do
|
2
|
-
let(:start_time) { 20.minutes.ago }
|
3
|
-
let(:finish_time) { 5.minutes.ago }
|
4
|
-
let(:
|
2
|
+
let(:start_time) { 20.minutes.ago.at_beginning_of_minute }
|
3
|
+
let(:finish_time) { 5.minutes.ago.at_beginning_of_minute }
|
4
|
+
let(:updated_time) { 1.minute.ago.at_beginning_of_minute }
|
5
|
+
let!(:first_resource) do
|
5
6
|
FactoryGirl.create(
|
6
7
|
:resource,
|
7
|
-
updated_at:
|
8
|
+
updated_at: updated_time,
|
8
9
|
indexed_at: start_time,
|
10
|
+
enqueued_at: start_time,
|
11
|
+
last_indexed_finished: start_time,
|
9
12
|
last_indexed_estimate: 7,
|
10
13
|
last_indexed_count: 5,
|
11
14
|
index_status: 1
|
12
15
|
)
|
13
16
|
end
|
14
|
-
let(:last_resource) do
|
17
|
+
let!(:last_resource) do
|
15
18
|
FactoryGirl.create(
|
16
19
|
:resource,
|
17
20
|
updated_at: finish_time,
|
18
|
-
indexed_at:
|
21
|
+
indexed_at: finish_time,
|
22
|
+
enqueued_at: start_time,
|
23
|
+
last_indexed_finished: finish_time,
|
19
24
|
last_indexed_estimate: 3,
|
20
25
|
last_indexed_count: 2,
|
21
26
|
index_status: 1
|
22
27
|
)
|
23
28
|
end
|
24
29
|
let(:resources) { [first_resource, last_resource] }
|
25
|
-
subject { described_class.new(
|
30
|
+
subject { described_class.new(Spotlight::Resource.all) }
|
26
31
|
let(:json) { JSON.parse(subject.to_json) }
|
27
32
|
|
28
33
|
before do
|
29
34
|
allow(subject).to receive_messages(completed_resources: resources)
|
30
35
|
end
|
31
36
|
|
32
|
-
describe '#
|
37
|
+
describe '#recently_in_progress?' do
|
33
38
|
context 'when the last resource has been updated within the allotted time' do
|
34
39
|
it 'is true' do
|
35
|
-
expect(subject).to
|
40
|
+
expect(subject).to be_recently_in_progress
|
36
41
|
end
|
37
42
|
end
|
38
43
|
|
39
44
|
context 'when any of the resources is makred as waiting' do
|
40
45
|
before do
|
41
|
-
expect(last_resource).to receive_messages(updated_at: 12.minutes.ago)
|
42
46
|
first_resource.waiting!
|
43
47
|
end
|
44
48
|
it 'is true' do
|
45
|
-
expect(subject).to
|
49
|
+
expect(subject).to be_recently_in_progress
|
46
50
|
end
|
47
51
|
end
|
48
52
|
|
49
53
|
context 'when the last resources has been updated outside of the allotted time ' do
|
50
54
|
before do
|
51
|
-
expect(last_resource).to receive_messages(
|
55
|
+
expect(last_resource).to receive_messages(last_indexed_finished: 12.minutes.ago)
|
52
56
|
end
|
53
57
|
it 'is false' do
|
54
|
-
expect(subject).not_to
|
58
|
+
expect(subject).not_to be_recently_in_progress
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
62
|
it 'is included in the json' do
|
59
|
-
expect(json['
|
63
|
+
expect(json['recently_in_progress']).to be true
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
63
|
-
describe '#
|
67
|
+
describe '#started_at' do
|
64
68
|
it 'returns the indexed_at attribute of the first resource' do
|
65
|
-
expect(subject.
|
69
|
+
expect(subject.started_at).to eq start_time
|
66
70
|
end
|
67
71
|
|
68
72
|
it 'is included in the json as a localized string' do
|
69
|
-
expect(json['
|
73
|
+
expect(json['started_at']).to eq I18n.l(start_time, format: :short)
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
73
|
-
describe '#
|
77
|
+
describe '#updated_at' do
|
74
78
|
it 'returns the updated_at attribute of the last resource' do
|
75
|
-
expect(subject.
|
79
|
+
expect(subject.updated_at).to eq updated_time
|
76
80
|
end
|
77
81
|
|
78
82
|
it 'is included in the json as a localized string under the updated_at attribute' do
|
79
|
-
expect(json['updated_at']).to eq I18n.l(
|
83
|
+
expect(json['updated_at']).to eq I18n.l(updated_time, format: :short)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#finished_at' do
|
88
|
+
it 'returns the updated_at attribute of the last resource' do
|
89
|
+
expect(subject.finished_at).to eq finish_time
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'is included in the json as a localized string under the updated_at attribute' do
|
93
|
+
expect(json['finished_at']).to eq I18n.l(finish_time, format: :short)
|
80
94
|
end
|
81
95
|
end
|
82
96
|
|