blacklight-spotlight 3.0.0.rc3 → 3.0.0.rc4
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/admin/reindex_monitor.js +1 -0
- data/app/assets/stylesheets/spotlight/browse_group_categories_block.scss +23 -0
- data/app/controllers/spotlight/catalog_controller.rb +4 -1
- data/app/controllers/spotlight/dashboards_controller.rb +1 -1
- data/app/controllers/spotlight/exhibits_controller.rb +1 -1
- data/app/helpers/spotlight/application_helper.rb +19 -0
- data/app/helpers/spotlight/pages_helper.rb +1 -1
- data/app/jobs/concerns/spotlight/job_tracking.rb +47 -0
- data/app/jobs/concerns/spotlight/limit_concurrency.rb +33 -0
- data/app/jobs/spotlight/add_uploads_from_csv.rb +6 -3
- data/app/jobs/spotlight/application_job.rb +8 -0
- data/app/jobs/spotlight/cleanup_job_trackers_job.rb +13 -0
- data/app/jobs/spotlight/default_thumbnail_job.rb +1 -3
- data/app/jobs/spotlight/reindex_exhibit_job.rb +36 -0
- data/app/jobs/spotlight/reindex_job.rb +49 -41
- data/app/jobs/spotlight/rename_sidecar_field_job.rb +2 -2
- data/app/jobs/spotlight/update_job_trackers_job.rb +20 -0
- data/app/models/concerns/spotlight/user.rb +2 -1
- data/app/models/spotlight/event.rb +13 -0
- data/app/models/spotlight/exhibit.rb +4 -14
- data/app/models/spotlight/job_tracker.rb +105 -0
- data/app/models/spotlight/reindex_progress.rb +44 -27
- data/app/models/spotlight/resource.rb +24 -58
- data/app/models/spotlight/resources/iiif_harvester.rb +10 -1
- data/app/models/spotlight/resources/iiif_manifest.rb +3 -1
- data/app/models/spotlight/resources/iiif_service.rb +1 -1
- data/app/models/spotlight/resources/json_upload.rb +12 -0
- data/app/models/spotlight/resources/upload.rb +25 -2
- data/app/models/spotlight/solr_document_sidecar.rb +2 -1
- data/app/services/spotlight/etl.rb +7 -0
- data/app/services/spotlight/etl/context.rb +52 -0
- data/app/services/spotlight/etl/executor.rb +194 -0
- data/app/services/spotlight/etl/loaders.rb +12 -0
- data/app/services/spotlight/etl/pipeline.rb +81 -0
- data/app/services/spotlight/etl/solr_loader.rb +96 -0
- data/app/services/spotlight/etl/sources.rb +25 -0
- data/app/services/spotlight/etl/step.rb +82 -0
- data/app/services/spotlight/etl/transforms.rb +64 -0
- data/app/services/spotlight/validity_checker.rb +5 -5
- data/app/views/spotlight/dashboards/_reindexing_activity.html.erb +6 -6
- data/app/views/spotlight/shared/_locale_picker.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +4 -3
- data/config/locales/spotlight.ar.yml +11 -1
- data/config/locales/spotlight.en.yml +3 -2
- data/db/migrate/20210122082032_create_job_trackers.rb +22 -0
- data/db/migrate/20210126123041_create_events.rb +15 -0
- data/lib/generators/spotlight/scaffold_resource_generator.rb +5 -13
- data/lib/spotlight/engine.rb +8 -1
- data/lib/spotlight/version.rb +1 -1
- data/spec/controllers/spotlight/catalog_controller_spec.rb +3 -1
- data/spec/examples.txt +1448 -1437
- data/spec/factories/job_trackers.rb +9 -0
- data/spec/features/add_items_spec.rb +9 -4
- data/spec/features/javascript/reindex_monitor_spec.rb +1 -1
- data/spec/features/site_users_management_spec.rb +4 -4
- data/spec/helpers/spotlight/pages_helper_spec.rb +8 -0
- data/spec/jobs/spotlight/reindex_exhibit_job_spec.rb +43 -0
- data/spec/jobs/spotlight/reindex_job_spec.rb +30 -59
- data/spec/models/spotlight/exhibit_spec.rb +3 -57
- data/spec/models/spotlight/reindex_progress_spec.rb +89 -87
- data/spec/models/spotlight/resource_spec.rb +69 -90
- data/spec/models/spotlight/resources/iiif_harvester_spec.rb +9 -10
- data/spec/models/spotlight/solr_document_sidecar_spec.rb +1 -0
- data/spec/services/spotlight/etl/context_spec.rb +66 -0
- data/spec/services/spotlight/etl/executor_spec.rb +149 -0
- data/spec/services/spotlight/etl/pipeline_spec.rb +22 -0
- data/spec/services/spotlight/etl/solr_loader_spec.rb +76 -0
- data/spec/services/spotlight/etl/step_spec.rb +70 -0
- data/spec/spec_helper.rb +2 -5
- data/spec/views/spotlight/dashboards/_reindexing_activity.html.erb_spec.rb +22 -19
- metadata +55 -15
- data/app/models/concerns/spotlight/resources/open_graph.rb +0 -36
- data/app/models/spotlight/reindexing_log_entry.rb +0 -42
- data/app/services/spotlight/resources/iiif_builder.rb +0 -19
- data/app/services/spotlight/solr_document_builder.rb +0 -77
- data/app/services/spotlight/upload_solr_document_builder.rb +0 -57
- data/spec/factories/reindexing_log_entries.rb +0 -54
- data/spec/models/spotlight/reindexing_log_entry_spec.rb +0 -129
- data/spec/models/spotlight/resources/open_graph_spec.rb +0 -65
- data/spec/services/spotlight/solr_document_builder_spec.rb +0 -66
@@ -43,7 +43,8 @@ describe 'Uploading a non-repository item', type: :feature do
|
|
43
43
|
expect(page).to have_content 'Object uploaded successfully.'
|
44
44
|
|
45
45
|
expect(Spotlight::Resource.last.upload.image.file.path).to end_with '800x600.png'
|
46
|
-
|
46
|
+
ensure
|
47
|
+
Blacklight.default_index.connection.delete_by_query 'spotlight_resource_type_ssim:spotlight/resources/uploads'
|
47
48
|
Blacklight.default_index.connection.commit
|
48
49
|
end
|
49
50
|
|
@@ -59,8 +60,8 @@ describe 'Uploading a non-repository item', type: :feature do
|
|
59
60
|
end
|
60
61
|
expect(page).to have_content 'Object uploaded successfully.'
|
61
62
|
expect(Spotlight::Resource.last.data['full_title_tesim']).to eq 'no-image'
|
62
|
-
|
63
|
-
Blacklight.default_index.connection.
|
63
|
+
ensure
|
64
|
+
Blacklight.default_index.connection.delete_by_query 'spotlight_resource_type_ssim:spotlight/resources/uploads'
|
64
65
|
Blacklight.default_index.connection.commit
|
65
66
|
end
|
66
67
|
|
@@ -113,6 +114,9 @@ describe 'Uploading a non-repository item', type: :feature do
|
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
117
|
+
Blacklight.default_index.connection.commit
|
118
|
+
visit current_path
|
119
|
+
|
116
120
|
click_link '800x600'
|
117
121
|
click_link 'Edit'
|
118
122
|
fill_in 'Title', with: 'This is a now an avatar'
|
@@ -123,7 +127,8 @@ describe 'Uploading a non-repository item', type: :feature do
|
|
123
127
|
|
124
128
|
expect(page).to have_content 'This is a now an avatar'
|
125
129
|
expect(Spotlight::Resource.last.upload.image.path).to end_with 'avatar.png'
|
126
|
-
|
130
|
+
ensure
|
131
|
+
Blacklight.default_index.connection.delete_by_query 'spotlight_resource_type_ssim:spotlight/resources/uploads'
|
127
132
|
Blacklight.default_index.connection.commit
|
128
133
|
end
|
129
134
|
end
|
@@ -8,7 +8,7 @@ describe 'Reindex Monitor', js: true, default_max_wait_time: 10 do
|
|
8
8
|
let(:exhibit_curator) { FactoryBot.create(:exhibit_curator, exhibit: exhibit) }
|
9
9
|
|
10
10
|
before do
|
11
|
-
|
11
|
+
exhibit.job_trackers.create(resource: exhibit, status: 'completed', job_class: 'Spotlight::ReindexExhibitJob')
|
12
12
|
login_as exhibit_curator
|
13
13
|
visit spotlight.admin_exhibit_catalog_path(exhibit)
|
14
14
|
end
|
@@ -44,13 +44,13 @@ describe 'Site users management', js: true do
|
|
44
44
|
|
45
45
|
expect(page).to have_css(:td, text: 'not-an-admin@example.com')
|
46
46
|
|
47
|
-
expect(page).to have_css(:a, text: 'Remove from admin role', count:
|
47
|
+
expect(page).to have_css(:a, text: 'Remove from admin role', count: 2)
|
48
48
|
within(all('table tbody tr:not([data-edit-for])').last) do
|
49
49
|
click_link 'Remove from admin role'
|
50
50
|
end
|
51
51
|
|
52
52
|
expect(page).to have_content 'User removed from site adminstrator role'
|
53
|
-
expect(page).to have_css(:a, text: 'Remove from admin role', count:
|
53
|
+
expect(page).to have_css(:a, text: 'Remove from admin role', count: 0)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'sends an invitation email to users who do not exist' do
|
@@ -68,7 +68,7 @@ describe 'Site users management', js: true do
|
|
68
68
|
click_link 'Add new administrator'
|
69
69
|
|
70
70
|
expect(page).to have_css('td', text: user.email)
|
71
|
-
# There
|
72
|
-
expect(page).to have_css(:a, text: 'Remove from admin role', count:
|
71
|
+
# There is just our admin user so no button
|
72
|
+
expect(page).to have_css(:a, text: 'Remove from admin role', count: 0)
|
73
73
|
end
|
74
74
|
end
|
@@ -106,6 +106,14 @@ describe Spotlight::PagesHelper, type: :helper do
|
|
106
106
|
it 'handles nil input' do
|
107
107
|
expect(helper.sir_trevor_markdown(nil)).to be_blank
|
108
108
|
end
|
109
|
+
|
110
|
+
it 'retains paragraphs' do
|
111
|
+
expect(helper.sir_trevor_markdown('<p>First Line</p><p>Second Line</p>').chomp).to match(%r{<p>First Line</p>\s*<p>Second Line</p>})
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'replaces line breaks with paragraphs' do
|
115
|
+
expect(helper.sir_trevor_markdown('First Line<br>Second Line').chomp).to match(%r{<p>First Line</p>\s*<p>Second Line</p>})
|
116
|
+
end
|
109
117
|
end
|
110
118
|
|
111
119
|
describe '#content_editor_class' do
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe Spotlight::ReindexExhibitJob do
|
4
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
FactoryBot.create_list(:resource, 10, exhibit: exhibit)
|
8
|
+
allow(Spotlight::ReindexJob).to receive(:perform_now)
|
9
|
+
allow(Spotlight::ReindexJob).to receive(:perform_later)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with a single batch' do
|
13
|
+
it 'runs the index job inline' do
|
14
|
+
described_class.perform_now(exhibit, batch_count: 1)
|
15
|
+
|
16
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_now).once.with(exhibit, anything)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a fixed batch count' do
|
21
|
+
it 'enqueues that number of batches' do
|
22
|
+
described_class.perform_now(exhibit, batch_count: 2)
|
23
|
+
|
24
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).twice.with(exhibit, hash_including(:start, :finish))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with a dynamically generated batch count' do
|
29
|
+
it 'enqueues the right number of batches' do
|
30
|
+
described_class.perform_now(exhibit, batch_count: nil, batch_size: 2)
|
31
|
+
|
32
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).exactly(5).times.with(exhibit, hash_including(:start, :finish))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with a dynamically generated batch size' do
|
37
|
+
it 'figues out that number of batches' do
|
38
|
+
described_class.perform_now(exhibit, batch_count: nil, batch_size: nil)
|
39
|
+
|
40
|
+
expect(Spotlight::ReindexJob).to have_received(:perform_later).exactly(3).times.with(exhibit, hash_including(:start, :finish))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -4,67 +4,14 @@ describe Spotlight::ReindexJob do
|
|
4
4
|
include ActiveJob::TestHelper
|
5
5
|
|
6
6
|
let(:exhibit) { FactoryBot.create(:exhibit) }
|
7
|
-
let(:resource) { FactoryBot.create(:resource) }
|
7
|
+
let(:resource) { FactoryBot.create(:resource, exhibit: exhibit) }
|
8
8
|
let(:user) { FactoryBot.create(:user) }
|
9
|
-
let(:log_entry) { Spotlight::ReindexingLogEntry.create(exhibit: exhibit, user: user) }
|
10
9
|
|
11
10
|
before do
|
12
11
|
ActiveJob::Base.queue_adapter = :test
|
13
12
|
allow_any_instance_of(Spotlight::Resource).to receive(:reindex)
|
14
13
|
end
|
15
14
|
|
16
|
-
context 'with an exhibit' do
|
17
|
-
subject { described_class.new(exhibit) }
|
18
|
-
|
19
|
-
before do
|
20
|
-
exhibit.resources << resource
|
21
|
-
exhibit.save
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'attempts to reindex every resource in the exhibit' do
|
25
|
-
# ActiveJob will reload the collection, so we go through a little trouble:
|
26
|
-
expect_any_instance_of(Spotlight::Resource).to receive(:reindex) do |thingy|
|
27
|
-
expect(exhibit.resources).to include thingy
|
28
|
-
end
|
29
|
-
|
30
|
-
subject.perform_now
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with a log_entry' do
|
34
|
-
subject { described_class.new(exhibit, log_entry) }
|
35
|
-
|
36
|
-
it 'marks the log entry as started' do
|
37
|
-
expect(log_entry).to receive(:in_progress!)
|
38
|
-
subject.perform_now
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'marks the log entry as successful if there is no error' do
|
42
|
-
expect(log_entry).to receive(:succeeded!)
|
43
|
-
subject.perform_now
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'marks the log entry as failed if there is an error' do
|
47
|
-
unexpected_error = StandardError.new
|
48
|
-
# it'd be more realistic to raise on resource#reindex, but that's already stubbed above, so this'll have to do
|
49
|
-
expect(subject).to receive(:perform).with(exhibit, log_entry).and_raise unexpected_error
|
50
|
-
expect(log_entry).to receive(:failed!)
|
51
|
-
expect { subject.perform_now }.to raise_error unexpected_error
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'updates the items_reindexed_estimate field on the log entry' do
|
55
|
-
expect(log_entry).to receive(:update).with(items_reindexed_estimate: 1)
|
56
|
-
subject.perform_now
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'passes log_entry to the resource.reindex call' do
|
60
|
-
# ActiveJob will reload the collection, so we go through a little trouble:
|
61
|
-
expect_any_instance_of(Spotlight::Resource).to receive(:reindex).with(log_entry).exactly(:once)
|
62
|
-
# expect(resource).to receive(:reindex).with(log_entry)
|
63
|
-
subject.perform_now
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
15
|
context 'with a resource' do
|
69
16
|
subject { described_class.new(resource) }
|
70
17
|
|
@@ -75,31 +22,55 @@ describe Spotlight::ReindexJob do
|
|
75
22
|
end
|
76
23
|
|
77
24
|
describe 'validity' do
|
78
|
-
subject { described_class.new(resource,
|
25
|
+
subject { described_class.new(resource, 'validity_token' => 'xyz') }
|
79
26
|
|
80
27
|
let(:mock_checker) { instance_double(Spotlight::ValidityChecker) }
|
81
28
|
|
82
29
|
before do
|
83
30
|
allow(described_class).to receive(:validity_checker).and_return(mock_checker)
|
84
|
-
allow(mock_checker).to receive(:mint).with(
|
31
|
+
allow(mock_checker).to receive(:mint).with(anything).and_return('xyz')
|
85
32
|
end
|
86
33
|
|
87
34
|
it 'mints a new validity token' do
|
88
|
-
expect { described_class.perform_later(resource) }.to have_enqueued_job(described_class).with(resource,
|
35
|
+
expect { described_class.perform_later(resource) }.to have_enqueued_job(described_class).with(resource, 'validity_token' => 'xyz')
|
89
36
|
end
|
90
37
|
|
91
38
|
it 'does nothing if the token is no longer valid' do
|
92
|
-
allow(mock_checker).to receive(:check).with(
|
39
|
+
allow(mock_checker).to receive(:check).with(subject, validity_token: 'xyz').and_return(false)
|
93
40
|
expect(resource).not_to receive(:reindex)
|
94
41
|
|
95
42
|
subject.perform_now
|
96
43
|
end
|
97
44
|
|
98
45
|
it 'indexes the resource if the token is valid' do
|
99
|
-
allow(mock_checker).to receive(:check).with(
|
46
|
+
allow(mock_checker).to receive(:check).with(subject, validity_token: 'xyz').and_return(true)
|
100
47
|
expect(resource).to receive(:reindex)
|
101
48
|
|
102
49
|
subject.perform_now
|
103
50
|
end
|
104
51
|
end
|
52
|
+
|
53
|
+
context 'with start and finish' do
|
54
|
+
it 'indexes the resources within that page' do
|
55
|
+
count = 0
|
56
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex) do
|
57
|
+
count += 1
|
58
|
+
end
|
59
|
+
|
60
|
+
described_class.perform_now(exhibit, start: 0, finish: resource.id)
|
61
|
+
|
62
|
+
expect(count).to eq 1
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'does not index resources off that page' do
|
66
|
+
count = 0
|
67
|
+
allow_any_instance_of(Spotlight::Resource).to receive(:reindex) do
|
68
|
+
count += 1
|
69
|
+
end
|
70
|
+
|
71
|
+
described_class.perform_now(exhibit, start: resource.id + 1, finish: resource.id + 500)
|
72
|
+
|
73
|
+
expect(count).to eq 0
|
74
|
+
end
|
75
|
+
end
|
105
76
|
end
|
@@ -253,48 +253,9 @@ describe Spotlight::Exhibit, type: :model do
|
|
253
253
|
describe '#reindex_later' do
|
254
254
|
subject { FactoryBot.create(:exhibit) }
|
255
255
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
let(:user) { nil }
|
260
|
-
|
261
|
-
it 'queues a reindex job for the exhibit, with nil user for the log entry' do
|
262
|
-
expect(subject).to receive(:new_reindexing_log_entry).with(nil).and_return(log_entry)
|
263
|
-
expect(Spotlight::ReindexJob).to receive(:perform_later).with(subject, log_entry)
|
264
|
-
subject.reindex_later
|
265
|
-
expect(log_entry.user).to be nil
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context 'non-nil user is provided' do
|
270
|
-
let(:user) { FactoryBot.build(:user) }
|
271
|
-
|
272
|
-
it 'queues a reindex job for the exhibit, with actual user for the log entry' do
|
273
|
-
expect(subject).to receive(:new_reindexing_log_entry).with(user).and_return(log_entry)
|
274
|
-
expect(Spotlight::ReindexJob).to receive(:perform_later).with(subject, log_entry)
|
275
|
-
subject.reindex_later user
|
276
|
-
expect(log_entry.user).to eq user
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
describe '#new_reindexing_log_entry' do
|
282
|
-
let(:user) { FactoryBot.build(:user) }
|
283
|
-
|
284
|
-
it 'returns a properly configured Spotlight::ReindexingLogEntry instance' do
|
285
|
-
reindexing_log_entry = subject.send(:new_reindexing_log_entry, user)
|
286
|
-
expect(reindexing_log_entry.exhibit).to eq subject
|
287
|
-
expect(reindexing_log_entry.user).to eq user
|
288
|
-
expect(reindexing_log_entry.items_reindexed_count).to eq 0
|
289
|
-
expect(reindexing_log_entry.unstarted?).to be true
|
290
|
-
end
|
291
|
-
|
292
|
-
it 'does not require user the user parameter' do
|
293
|
-
reindexing_log_entry = subject.send(:new_reindexing_log_entry)
|
294
|
-
expect(reindexing_log_entry.exhibit).to eq subject
|
295
|
-
expect(reindexing_log_entry.user).to be nil
|
296
|
-
expect(reindexing_log_entry.items_reindexed_count).to eq 0
|
297
|
-
expect(reindexing_log_entry.unstarted?).to be true
|
256
|
+
it 'queues a reindex job for the exhibit' do
|
257
|
+
expect(Spotlight::ReindexExhibitJob).to receive(:perform_later).with(subject, user: nil)
|
258
|
+
subject.reindex_later
|
298
259
|
end
|
299
260
|
end
|
300
261
|
|
@@ -366,24 +327,9 @@ describe Spotlight::Exhibit, type: :model do
|
|
366
327
|
end
|
367
328
|
|
368
329
|
describe '#reindex_progress' do
|
369
|
-
let!(:reindexing_log_entries) do
|
370
|
-
[
|
371
|
-
FactoryBot.create(:unstarted_reindexing_log_entry, exhibit: exhibit),
|
372
|
-
FactoryBot.create(:reindexing_log_entry, exhibit: exhibit),
|
373
|
-
in_progress_entry,
|
374
|
-
FactoryBot.create(:failed_reindexing_log_entry, exhibit: exhibit),
|
375
|
-
FactoryBot.create(:unstarted_reindexing_log_entry, exhibit: exhibit)
|
376
|
-
]
|
377
|
-
end
|
378
|
-
|
379
|
-
let(:in_progress_entry) do
|
380
|
-
FactoryBot.create(:in_progress_reindexing_log_entry, exhibit: exhibit)
|
381
|
-
end
|
382
|
-
|
383
330
|
it 'returns the latest log entry that is not unstarted' do
|
384
331
|
reindex_progress = subject.reindex_progress
|
385
332
|
expect(reindex_progress).to be_a Spotlight::ReindexProgress
|
386
|
-
expect(reindex_progress.current_log_entry).to eq in_progress_entry
|
387
333
|
end
|
388
334
|
end
|
389
335
|
|
@@ -1,122 +1,124 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
describe Spotlight::ReindexProgress, type: :model do
|
4
|
-
|
5
|
-
|
4
|
+
subject(:progress) { described_class.new(exhibit) }
|
5
|
+
|
6
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
7
|
+
let!(:job_tracker) do
|
8
|
+
FactoryBot.create(
|
9
|
+
:job_tracker,
|
10
|
+
resource: exhibit,
|
11
|
+
on: exhibit,
|
12
|
+
job_class: 'Spotlight::ReindexExhibitJob',
|
13
|
+
updated_at: Time.zone.now,
|
14
|
+
**job_tracker_args
|
15
|
+
)
|
6
16
|
end
|
17
|
+
let(:job_tracker_args) { {} }
|
7
18
|
|
8
|
-
|
19
|
+
context 'with a completed job' do
|
20
|
+
let(:job_tracker_args) { { status: 'completed', data: { progress: 50, total: 50 } } }
|
9
21
|
|
10
|
-
|
11
|
-
|
12
|
-
|
22
|
+
it 'reports on reindexing progress' do
|
23
|
+
expect(progress.as_json).to include(
|
24
|
+
completed: 50,
|
25
|
+
total: 50,
|
26
|
+
finished: true,
|
27
|
+
errored: false,
|
28
|
+
recently_in_progress: true
|
29
|
+
)
|
13
30
|
end
|
14
31
|
end
|
15
32
|
|
16
|
-
|
17
|
-
|
18
|
-
expect(subject.updated_at).to eq reindexing_log_entry.updated_at
|
19
|
-
end
|
20
|
-
end
|
33
|
+
context 'with a failed job' do
|
34
|
+
let(:job_tracker_args) { { status: 'failed', data: { progress: 32, total: 50 } } }
|
21
35
|
|
22
|
-
|
23
|
-
|
24
|
-
|
36
|
+
it 'reports on reindexing progress' do
|
37
|
+
expect(progress.as_json).to include(
|
38
|
+
completed: 32,
|
39
|
+
total: 50,
|
40
|
+
finished: true,
|
41
|
+
errored: true
|
42
|
+
)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
|
28
|
-
|
29
|
-
|
30
|
-
|
46
|
+
context 'with an in-progress job' do
|
47
|
+
before do
|
48
|
+
FactoryBot.create(:job_tracker, on: job_tracker, resource: exhibit, data: { progress: 32, total: 32 }, status: 'completed')
|
49
|
+
FactoryBot.create(:job_tracker, on: job_tracker, resource: exhibit, data: { progress: 16, total: 50 }, status: 'in_progress')
|
31
50
|
end
|
32
|
-
end
|
33
51
|
|
34
|
-
|
35
|
-
it 'returns items_reindexed_estimate for current_log_entry' do
|
36
|
-
expect(subject.total).to be 12
|
37
|
-
end
|
38
|
-
end
|
52
|
+
let(:job_tracker_args) { { status: 'in_progress' } }
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
it 'harvests total and completed data from the child jobs' do
|
55
|
+
expect(progress.as_json).to include(
|
56
|
+
completed: 48,
|
57
|
+
total: 82
|
58
|
+
)
|
43
59
|
end
|
44
|
-
end
|
45
60
|
|
46
|
-
|
47
|
-
|
48
|
-
expect(subject).to be_errored
|
49
|
-
end
|
50
|
-
end
|
61
|
+
it 'is not completed until all the child jobs are finished' do
|
62
|
+
job_tracker.update(status: 'failed')
|
51
63
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
recently_in_progress: subject.recently_in_progress?,
|
56
|
-
started_at: I18n.l(reindexing_log_entry.start_time, format: :long),
|
57
|
-
finished_at: I18n.l(reindexing_log_entry.end_time, format: :long),
|
58
|
-
updated_at: I18n.l(reindexing_log_entry.updated_at, format: :long),
|
59
|
-
total: subject.total,
|
60
|
-
completed: subject.completed,
|
61
|
-
errored: subject.errored?,
|
62
|
-
finished: subject.finished?
|
64
|
+
expect(progress.as_json).to include(
|
65
|
+
finished: false,
|
66
|
+
errored: true
|
63
67
|
)
|
64
68
|
end
|
65
69
|
end
|
66
70
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
it 'returns true' do
|
72
|
-
expect(subject).to be_recently_in_progress
|
73
|
-
end
|
71
|
+
context 'with no job' do
|
72
|
+
before do
|
73
|
+
job_tracker.delete
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
76
|
+
it 'reports on reindexing progress' do
|
77
|
+
expect(progress.as_json).to include(
|
78
|
+
completed: 0,
|
79
|
+
total: 0,
|
80
|
+
finished: false,
|
81
|
+
errored: false,
|
82
|
+
recently_in_progress: false
|
83
|
+
)
|
82
84
|
end
|
85
|
+
end
|
83
86
|
|
84
|
-
|
85
|
-
|
87
|
+
context 'with multiple job trackers' do
|
88
|
+
let(:job_tracker_args) { { status: 'in_progress' } }
|
89
|
+
|
90
|
+
before do
|
91
|
+
FactoryBot.create(
|
92
|
+
:job_tracker,
|
93
|
+
resource: exhibit,
|
94
|
+
on: exhibit,
|
95
|
+
job_class: 'Spotlight::ReindexExhibitJob',
|
96
|
+
updated_at: Time.zone.now,
|
97
|
+
status: 'completed'
|
98
|
+
)
|
99
|
+
end
|
86
100
|
|
87
|
-
|
88
|
-
|
89
|
-
end
|
101
|
+
it 'uses the currently in-progress tracker' do
|
102
|
+
expect(progress.as_json).to include(finished: false)
|
90
103
|
end
|
91
104
|
end
|
92
105
|
|
93
|
-
context '
|
94
|
-
let(:
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
expect(subject.completed).to be nil
|
105
|
-
expect(subject.errored?).to be false
|
106
|
-
expect(subject.send(:localized_start_time)).to be nil
|
107
|
-
expect(subject.send(:localized_finish_time)).to be nil
|
108
|
-
expect(subject.send(:localized_updated_time)).to be nil
|
109
|
-
expect(subject.as_json).to eq(
|
110
|
-
recently_in_progress: false,
|
111
|
-
started_at: nil,
|
112
|
-
finished_at: nil,
|
113
|
-
updated_at: nil,
|
114
|
-
total: nil,
|
115
|
-
completed: nil,
|
116
|
-
errored: false,
|
117
|
-
finished: false
|
106
|
+
context 'with multiple in-progress trackers' do
|
107
|
+
let(:job_tracker_args) { { status: 'in_progress' } }
|
108
|
+
|
109
|
+
before do
|
110
|
+
FactoryBot.create(
|
111
|
+
:job_tracker,
|
112
|
+
resource: exhibit,
|
113
|
+
on: exhibit,
|
114
|
+
job_class: 'Spotlight::ReindexExhibitJob',
|
115
|
+
updated_at: Time.zone.now - 5.years,
|
116
|
+
status: 'in_progress'
|
118
117
|
)
|
119
118
|
end
|
120
|
-
|
119
|
+
|
120
|
+
it 'uses the most recently updated tracker' do
|
121
|
+
expect(Time.zone.parse(progress.as_json[:updated_at]).year).to eq job_tracker.updated_at.year
|
122
|
+
end
|
121
123
|
end
|
122
124
|
end
|