File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed
Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1+ class WarmUpCache
2+ lev_routine transaction : :no_transaction
3+
4+ protected
5+
6+ def exec
7+ Exercise . chainable_latest . find_in_batches ( batch_size : 100 ) do |exercises |
8+ Api ::V1 ::Exercises ::SearchRepresenter . new ( items : exercises ) . to_hash (
9+ user_options : { can_view_solutions : true }
10+ )
11+ end
12+
13+ VocabTerm . chainable_latest . find_in_batches ( batch_size : 100 ) do |vocab_terms |
14+ Api ::V1 ::Vocabs ::TermSearchRepresenter . new ( items : vocab_terms ) . to_hash
15+ end
16+ end
17+ end
Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ namespace :cron do
55 Rails . logger . info 'UpdateSlugs.call'
66 OpenStax ::RescueFrom . this { UpdateSlugs . call }
77
8+ Rails . logger . info 'WarmUpCache.call'
9+ OpenStax ::RescueFrom . this { WarmUpCache . call }
10+
811 Rails . logger . debug 'Finished daily cron'
912 end
1013end
Original file line number Diff line number Diff line change 99
1010 before { Rake ::Task [ 'cron:day' ] . reenable }
1111
12- it 'calls the UpdateSlugs lev routine ' do
12+ it 'calls the UpdateSlugs and WarmUpCache lev routines ' do
1313 expect ( UpdateSlugs ) . to receive ( :call )
14+ expect ( WarmUpCache ) . to receive ( :call )
1415
1516 Rake . application . invoke_task 'cron:day'
1617 end
Original file line number Diff line number Diff line change 1+ require 'rails_helper'
2+
3+ RSpec . describe WarmUpCache , type : :routine do
4+ before do
5+ 5 . times do
6+ FactoryBot . create :exercise
7+ FactoryBot . create :exercise , :published
8+ FactoryBot . create :vocab_term , vocab_distractors_count : 1
9+ FactoryBot . create :vocab_term , :published , vocab_distractors_count : 1
10+ end
11+ end
12+
13+ it 'caches all exercises and vocab terms' do
14+ expect { described_class . call } . to (
15+ change { Rails . cache . instance_variable_get ( :@data ) . count } . by ( 60 )
16+ )
17+
18+ expect { described_class . call } . not_to (
19+ change { Rails . cache . instance_variable_get ( :@data ) . count }
20+ )
21+ end
22+ end
You can’t perform that action at this time.
0 commit comments