Skip to content

Commit

Permalink
Deal with reloadable constants that get autoloaded during initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
randalldfloyd committed Oct 8, 2024
1 parent c54a552 commit 03ad9f9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
37 changes: 20 additions & 17 deletions .koppie/config/initializers/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,26 @@
Qa::Authorities::Local.register_subauthority('languages', 'Qa::Authorities::Local::TableBasedAuthority')
Qa::Authorities::Local.register_subauthority('genres', 'Qa::Authorities::Local::TableBasedAuthority')

custom_queries = [Hyrax::CustomQueries::Navigators::CollectionMembers,
Hyrax::CustomQueries::Navigators::ChildCollectionsNavigator,
Hyrax::CustomQueries::Navigators::ParentCollectionsNavigator,
Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator,
Hyrax::CustomQueries::Navigators::ChildWorksNavigator,
Hyrax::CustomQueries::Navigators::ParentWorkNavigator,
Hyrax::CustomQueries::Navigators::FindFiles,
Hyrax::CustomQueries::FindAccessControl,
Hyrax::CustomQueries::FindCollectionsByType,
Hyrax::CustomQueries::FindFileMetadata,
Hyrax::CustomQueries::FindIdsByModel,
Hyrax::CustomQueries::FindManyByAlternateIds,
Hyrax::CustomQueries::FindModelsByAccess,
Hyrax::CustomQueries::FindCountBy,
Hyrax::CustomQueries::FindByDateRange]
custom_queries.each do |handler|
Hyrax.query_service.custom_queries.register_query_handler(handler)
Rails.application.reloader.to_prepare do
custom_queries = [Hyrax::CustomQueries::Navigators::CollectionMembers,
Hyrax::CustomQueries::Navigators::ChildCollectionsNavigator,
Hyrax::CustomQueries::Navigators::ParentCollectionsNavigator,
Hyrax::CustomQueries::Navigators::ChildFileSetsNavigator,
Hyrax::CustomQueries::Navigators::ChildWorksNavigator,
Hyrax::CustomQueries::Navigators::ParentWorkNavigator,
Hyrax::CustomQueries::Navigators::FindFiles,
Hyrax::CustomQueries::FindAccessControl,
Hyrax::CustomQueries::FindCollectionsByType,
Hyrax::CustomQueries::FindFileMetadata,
Hyrax::CustomQueries::FindIdsByModel,
Hyrax::CustomQueries::FindManyByAlternateIds,
Hyrax::CustomQueries::FindModelsByAccess,
Hyrax::CustomQueries::FindCountBy,
Hyrax::CustomQueries::FindByDateRange]
custom_queries.each do |handler|
Hyrax.query_service.custom_queries.register_query_handler(handler)
end
end


ActiveFedora.init(solr_config_path: Rails.root.join('config', 'solr.yml'))
39 changes: 21 additions & 18 deletions .koppie/config/initializers/riiif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,35 @@
module Hyrax
# Adds file locking to Riiif::File
# @see RiiifFileResolver
class RiiifFile < Riiif::File
include ActiveSupport::Benchmarkable

attr_reader :id
def initialize(input_path, tempfile = nil, id:)
super(input_path, tempfile)
raise(ArgumentError, "must specify id") if id.blank?
@id = id
end
Rails.application.reloader.to_prepare do
class RiiifFile < Riiif::File
include ActiveSupport::Benchmarkable

attr_reader :id
def initialize(input_path, tempfile = nil, id:)
super(input_path, tempfile)
raise(ArgumentError, "must specify id") if id.blank?
@id = id
end

# Wrap extract in a read lock and benchmark it
def extract(transformation, image_info = nil)
Riiif::Image.file_resolver.file_locks[id].with_read_lock do
benchmark "RiiifFile extracted #{path} with #{transformation.to_params}", level: :debug do
super
# Wrap extract in a read lock and benchmark it
def extract(transformation, image_info = nil)
Riiif::Image.file_resolver.file_locks[id].with_read_lock do
benchmark "RiiifFile extracted #{path} with #{transformation.to_params}", level: :debug do
super
end
end
end
end

private
private

def logger
Hyrax.logger
def logger
Hyrax.logger
end
end
end


class RiiifFileResolver
include ActiveSupport::Benchmarkable

Expand Down
8 changes: 8 additions & 0 deletions app/services/hyrax/workflow.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true
module Hyrax
module Workflow
extend ActiveSupport::Autoload

autoload :WorkflowFactory
end
end
6 changes: 4 additions & 2 deletions config/initializers/listeners.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

Hyrax.publisher.subscribe(Hyrax::Listeners::ActiveFedoraACLIndexListener.new) unless Hyrax.config.disable_wings

Hyrax.publisher.default_listeners.each do |listener|
Hyrax.publisher.subscribe(listener)
Rails.application.reloader.to_prepare do
Hyrax.publisher.default_listeners.each do |listener|
Hyrax.publisher.subscribe(listener)
end
end

# Publish events from old style Hyrax::Callbacks to trigger the listeners
Expand Down
5 changes: 5 additions & 0 deletions lib/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module Hyrax
autoload :ResourceSync
autoload :Zotero
autoload :Listeners
autoload :Workflow
autoload :SimpleSchemaLoader
autoload :VirusScanner
autoload :DerivativeBucketedStorage
#autoload :CustomQueries
end

##
Expand Down

0 comments on commit 03ad9f9

Please sign in to comment.