class Longleaf::ServiceManager
Manager which provides preservation service definitions based on their mappings
Attributes
Public Class Methods
@param definition_manager
[ServiceDefinitionManager] the service definition manager @param mapping_manager
[ServiceMappingManager] the mapping of services to locations @param app_manager [ApplicationConfigManager] manager for storage locations
# File lib/longleaf/services/service_manager.rb, line 13 def initialize(definition_manager:, mapping_manager:, app_manager:) raise ArgumentError.new('Service definition manager required') if definition_manager.nil? raise ArgumentError.new('Service mappings manager required') if mapping_manager.nil? raise ArgumentError.new('Storage location manager required') if app_manager.nil? @definition_manager = definition_manager @mapping_manager = mapping_manager @app_manager = app_manager @service_class_cache = ServiceClassCache.new(app_manager) end
Public Instance Methods
Determines if a service is applicable for a specific preservation event @param service_name [String] name of the service being evaluated @param event [String] name of the event to check against @return [Boolean] true if the service is applicable for the event
# File lib/longleaf/services/service_manager.rb, line 61 def applicable_for_event?(service_name, event) service(service_name).is_applicable?(event) end
List definitions for services which are applicable to the given criteria @param location [String] name of the locations to lookup @param event [String] name of the preservation event taking place @return [Array] List of service definitions which match the provided criteria
# File lib/longleaf/services/service_manager.rb, line 52 def list_service_definitions(location: nil, event: nil) names = list_services(location: location, event: event) names.map { |name| @definition_manager.services[name] } end
List the names of services which are applicable to the given criteria @param location [String] name of the locations to lookup @param event [String] name of the preservation event taking place @return [Array] a list of service names which match the provided criteria
# File lib/longleaf/services/service_manager.rb, line 38 def list_services(location: nil, event: nil) service_names = @mapping_manager.list_services(location) if !event.nil? # Filter service names down by event service_names.select { |name| applicable_for_event?(name, event) } else service_names end end
Perform the specified service on the file record, in the context of the specified event @param service_name [String] name of the service @param file_rec [FileRecord] file record to perform service upon @param event [String] name of the event service is being performed within.
# File lib/longleaf/services/service_manager.rb, line 89 def perform_service(service_name, file_rec, event) definition = @definition_manager.services[service_name] service = @service_class_cache.service_instance(definition) service.perform(file_rec, event) end
Return a service instance instance for provided service name. @param service_name [String] name of the service @return Preservation service class for the provided name @raise ArgumentError if service_name does not reference an existing service
# File lib/longleaf/services/service_manager.rb, line 27 def service(service_name) raise ArgumentError.new('Service name is required') if service_name.nil? || service_name.empty? raise ArgumentError.new("No service with name #{service_name}") unless @definition_manager.services.key?(service_name) definition = @definition_manager.services[service_name] @service_class_cache.service_instance(definition) end
Determine if a service should run for a particular file based on the service's definition and the file's service related metadata. @param service_name [String] name of the service being evaluated @param md_rec [MetadataRecord] metadata record for the file being evaluated @return [Boolean] true if the service should be run.
# File lib/longleaf/services/service_manager.rb, line 70 def service_needed?(service_name, md_rec) service_rec = md_rec.service(service_name) return true if !service_rec.nil? && service_rec.run_needed definition = @definition_manager.services[service_name] next_run = ServiceDateHelper.next_run_needed(md_rec, definition) return false if next_run.nil? # If next run timestamp has passed then service is needed now = ServiceDateHelper.formatted_timestamp now >= next_run end