Skip to content

auto-refresh config's boutiques descriptor #1174 #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions BrainPortal/app/models/tool_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,13 @@ def self.register_descriptor(descriptor, tool_name, tool_version) #:nodoc:
def self.registered_boutiques_descriptor(tool_name, tool_version) #:nodoc:
@_descriptors_ ||= {}
key = [ tool_name, tool_version ] # two strings
@_descriptors_[key] = @_descriptors_[key]&.reload_if_file_timestamp_changed
@_descriptors_[key]
end

# This method returns a +BoutiquesDescriptor+ object associated with the
# with tool config either from cache, or if a specific path given from the corresponding file
# is specified from that file
def boutiques_descriptor
path = boutiques_descriptor_path.presence
if ! path
Expand Down
18 changes: 16 additions & 2 deletions BrainPortal/lib/boutiques_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class ContainerImage < RestrictedHash ; end
class BoutiquesDescriptor

attr_accessor :from_file # not a hash attribute; a file name, for info
attr_accessor :mtime_of_file # not a hash attribute, a file timestamp, for caching


def initialize(hash={})
Expand All @@ -175,18 +176,31 @@ def self.new_from_string(text)

def self.new_from_file(path)
obj = self.new_from_string(File.read(path))
obj.from_file = path
obj.from_file = path
obj.mtime_of_file = File.mtime(path)
obj
end

# Refreshes the descriptor from the file if the file has changed.
# Returns self if the file has not changed, or a new descriptor
# if the file has changed. This is useful for quickly updating the descriptor(s)
# for small corrections or updates. Presently it is used only for the
# boutiques present in boutiques-descriptor subdirectories.
def reload_if_file_timestamp_changed
filepath = self.from_file
return self if filepath.blank? || (File.mtime(filepath) - self.mtime_of_file ).abs < 1
self.class.new_from_file(filepath)
end

def validate
BoutiquesSupport.validate(self) # amazingly, the JSON validator also work with our descriptor class
end

# When dup'ing, also copy the from_file attribute
def dup #:nodoc:
copy = super
copy.from_file = self.from_file
copy.from_file = self.from_file
copy.mtime_of_file = self.mtime_of_file
copy
end

Expand Down