Skip to content

Commit 3f9dc01

Browse files
config's boutiques descriptor auto-refresh #1174
1 parent 4a3547e commit 3f9dc01

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

BrainPortal/app/models/tool_config.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,15 +593,21 @@ def self.register_descriptor(descriptor, tool_name, tool_version) #:nodoc:
593593
def self.registered_boutiques_descriptor(tool_name, tool_version) #:nodoc:
594594
@_descriptors_ ||= {}
595595
key = [ tool_name, tool_version ] # two strings
596+
@_descriptors_[key] = @_descriptors_[key]&.reload_if_file_timestamp_changed
596597
@_descriptors_[key]
597598
end
598599

599600
def boutiques_descriptor
601+
if @_descriptor_
602+
@_descriptor_ = @_descriptor_.reload_if_file_timestamp_changed
603+
key = [ self.tool.name, self.version_name ] # two strings
604+
@_descriptors_[key] = @_descriptor_
605+
return @_descriptor_
606+
end
600607
path = boutiques_descriptor_path.presence
601608
if ! path
602609
return self.class.registered_boutiques_descriptor(self.tool.name, self.version_name)
603610
end
604-
return @_descriptor_ if @_descriptor_
605611
path = Pathname.new(path)
606612
path = Pathname.new(CBRAIN::BoutiquesDescriptorsPlugins_Dir) + path if path.relative?
607613
@_descriptor_ = BoutiquesSupport::BoutiquesDescriptor.new_from_file(path)

BrainPortal/lib/boutiques_support.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def self.validate(json)
5252
# initialize above (top_prop_names etc).
5353
BoutiquesDescriptor = Class.new(RestrictedHash) do |klass|
5454

55-
allowed_keys top_prop_names # 'name', 'author' etc
56-
attr_accessor :from_file # not a hash attribute; a file name, for info
55+
allowed_keys top_prop_names # 'name', 'author' etc
56+
attr_accessor :from_file # not a hash attribute; a file name, for info
57+
attr_accessor :mtime_of_file # not a hash attribute, a file timestamp, for caching
5758

5859
Input = Class.new(RestrictedHash) { allowed_keys input_prop_names }
5960
OutputFile = Class.new(RestrictedHash) { allowed_keys output_prop_names }
@@ -89,18 +90,26 @@ def self.new_from_string(text)
8990

9091
def self.new_from_file(path)
9192
obj = self.new_from_string(File.read(path))
92-
obj.from_file = path
93+
obj.from_file = path
94+
obj.mtime_of_file = File.mtime(path)
9395
obj
9496
end
9597

98+
def reload_if_file_timestamp_changed()
99+
filepath = self.from_file
100+
return self if filepath.blank? || File.mtime(filepath) == self.mtime_of_file
101+
self.class.new_from_file(filepath)
102+
end
103+
96104
def validate
97105
BoutiquesSupport.validate(self) # amazingly, the JSON validator also work with our descriptor class
98106
end
99107

100108
# When dup'ing, also copy the from_file attribute
101109
def dup #:nodoc:
102110
copy = super
103-
copy.from_file = self.from_file
111+
copy.from_file = self.from_file
112+
copy.mtime_of_file = self.mtime_of_file
104113
copy
105114
end
106115

0 commit comments

Comments
 (0)