-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only check for solr alias changes on a timer
The implementation of `solr_cloud-connection` is purposefully chatty, not caching anything because during the admin cycle, you want to see your changes reflected immediatley and the number of operations is generally small. My use of uncached values (checking the name of the collection underlying an alias) on what turned out to be basically every call was disastrous. This PR creates an instance of [Concurrent::TimerTask](https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent/TimerTask.html) that runs the check, and updates if needed, every 20 seconds. Notable changes are: * All the logic about updates is moved into `config/initializers/solr_admin_cache.rb` * The formerly-recursive method of determining the underlying collection name (because it's legal, in general, to have aliass that point to other aliases) has been removed, since we just don't need it. * The cached values are stored in `Concurrent::Atom` instances in the Services module with everything else * `load_local_config.rb` basically just calls `#value` on the Services values. * The footer now shows, ridiculously, the time down to the second. This is purely to make testing easier, because seeing a change in the footer date is an easy way to know the change has been made.
- Loading branch information
1 parent
436321b
commit fdb8aa1
Showing
6 changed files
with
50 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
S = Dromedary::Services | ||
|
||
# Set up some places to work | ||
S.register(:hyp_to_bibid) { Concurrent::Atom.new(:no_hyp_to_bib_id_yet) } | ||
S.register(:collection_creation_date) { Concurrent::Atom.new(:no_creation_date_yet) } | ||
S.register(:underlying_collection_name) {Concurrent::Atom.new(:no_underlying_name_yet) } | ||
|
||
|
||
# Update the underlying concurrent variables. | ||
# If the collection name underlying the (presumed) alias we're working with changes, | ||
# update the collection-specific data and reset our understanding of the | ||
# current collection name. | ||
def update_timeout_variables | ||
Rails.logger.warn "################# CHECK FOR UPDATE ########################" | ||
collection = S[:solr_current_collection] | ||
actual_current_underlying_collection_name = collection.collection.name | ||
expected_underlying_collection_name = S[:underlying_collection_name].value | ||
if actual_current_underlying_collection_name != expected_underlying_collection_name | ||
Rails.logger.warn "################# PERFORMING UPDATE ########################" | ||
S[:hyp_to_bibid].reset MedInstaller::HypToBibId.get_from_solr(collection: collection) | ||
S[:collection_creation_date].reset Dromedary.compute_collection_creation_date(actual_current_underlying_collection_name) | ||
S[:underlying_collection_name].reset actual_current_underlying_collection_name | ||
end | ||
end | ||
|
||
# The timer, with `run_now`, is supposed to run immediately, but I keep getting not-set-yet | ||
# errors, so we'll run it once manually on startup. | ||
update_timeout_variables | ||
|
||
# Run the update method ever 20 seconds | ||
collection_timer = Concurrent::TimerTask.new(execution_interval: 20, run_now: true) do | ||
update_timeout_variables | ||
end | ||
# Need to call #execute to actually fire up the timer | ||
collection_timer.execute |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters