Skip to content
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
1 change: 1 addition & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def log(txt)

around_perform do |job, block|
Rails.logger.info "Run job - #{job}"
Application.refresh_dynamic_defs
block.call
rescue StandardError, FsException, FphsException, RuntimeError, IOError => e
begin
Expand Down
11 changes: 11 additions & 0 deletions app/models/dynamic/def_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ def refresh_outdated
# (and therefore we are on our first load and everything will have just been set up) just return
return if utd || utd.nil?

if @config_library_only_change
Rails.logger.warn "Refreshing config library dependents for #{name}"
reset_active_model_configurations!
active.each do |d|
next unless d.options_text&.include?('# @library ')

d.force_option_config_parse(raise_bad_configs: false)
end
return
end

Rails.logger.warn "Refreshing outdated #{name}"
reset_active_model_configurations!
defs = active_model_configurations.reorder('').order('updated_at desc nulls last')
Expand Down
21 changes: 19 additions & 2 deletions app/models/dynamic/def_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,23 @@ def add_nested_attribute(attrib)
# @return [DateTime]
def latest_stored_update(using: nil)
using ||= active_model_configurations
using
@latest_def_update = using
.select(:updated_at)
.reorder('')
.order('updated_at desc nulls last')
.limit(1)
.pluck(:updated_at)
.first

cl_update = Admin::ConfigLibrary
.where(format: 'yaml')
.reorder('')
.order('updated_at desc nulls last')
.limit(1)
.pluck(:updated_at)
.first

[@latest_def_update, cl_update].compact.max
end

#
Expand All @@ -257,18 +267,25 @@ def up_to_date?

if !lu && !@prev_latest_update
# They match if both nil
@config_library_only_change = false
true
elsif lu && @prev_latest_update && (lu - @prev_latest_update).abs < 2
# Consider them a match if they are within 2 seconds of one another,
# accounting for the difference between Rails and DB times
@config_library_only_change = false
true
elsif @prev_latest_update.nil?
# The remembered value was nil, so let the caller know this
self.prev_latest_update = lu
@prev_latest_def_update = @latest_def_update
@config_library_only_change = false
nil
else
# There was no match
# There was no match - check if only config libraries changed
@config_library_only_change = @prev_latest_def_update && @latest_def_update &&
(@latest_def_update - @prev_latest_def_update).abs < 2
self.prev_latest_update = lu
@prev_latest_def_update = @latest_def_update
false
end
end
Expand Down
Loading