Skip to content
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

new consistency check at boot time: Userfile and CbrainTask classes STI #969 #1369

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
8 changes: 8 additions & 0 deletions Bourreau/lib/bourreau_system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,12 @@ def self.z000_ensure_we_have_a_forwarded_ssh_agent #:nodoc:

end



def self.z010_ensure_task_sti_enabled #:nodoc:
myself = RemoteResource.current_resource
local_tasks = CbrainTask.where(bourreau_id: myself.id)
validate_sti(local_tasks)
end

end
21 changes: 21 additions & 0 deletions BrainPortal/lib/cbrain_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,26 @@ def self.check(checks_to_run)

end

protected

# helper method to runs a query and checks that type column contains
# already loaded objects; on mild issues (forgot run rake install etc...)
# in developer env gives warning but fails execution in production or test environment
def self.validate_sti(query)

table = query&.table_name || 'a table'

#----------------------------------------------------------------------------
puts "C> Checking STI column of #{table} ..."
#----------------------------------------------------------------------------

level = Rails.env.development? ? 'Warning' : 'Error'
messages = query.distinct.pluck(:type).map do |name|
"C> \t- #{level}: Invalid STI type: " + name unless name.safe_constantize
end.compact
puts messages
raise "Invalid types in the STI column of #{table}" unless messages.empty? || level == "Warning"
end

end

4 changes: 4 additions & 0 deletions BrainPortal/lib/cbrain_system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def self.a050_check_data_provider_cache_wipe #:nodoc:



def self.a060_ensure_userfile_sti_enabled #:nodoc:
validate_sti(Userfile)
end

def self.a080_ensure_set_starttime_revision #:nodoc:
#-----------------------------------------------------------------------------
puts "C> Current application tag or revision: #{CBRAIN::CBRAIN_StartTime_Revision}"
Expand Down
6 changes: 6 additions & 0 deletions BrainPortal/lib/portal_system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,11 @@ def self.z010_ensure_we_have_a_ssh_agent_locker #:nodoc:
)
end



def self.z020_ensure_task_sti_enabled #:nodoc:
validate_sti(CbrainTask)
end

end

Loading