states.rb revision 6097dbf238b09e567fd30f7dd8fd2b6974f74259
758N/A#
758N/A# states:
758N/A# * pending
758N/A# * fetching
758N/A# * processing
758N/A# * failed
758N/A# * done
758N/A#
758N/Amodule OntologyVersion::States
758N/A extend ActiveSupport::Concern
758N/A
758N/A include StateUpdater
758N/A
758N/A TERMINAL_STATES = State::TERMINAL_STATES
758N/A
758N/A included do
758N/A after_save :after_update_state, if: :change_applicable?
758N/A end
758N/A
758N/A def change_applicable?
758N/A state_changed? &&
758N/A parent.nil?
758N/A end
758N/A
758N/A def state_message
758N/A msg = [state]
758N/A if last_error
758N/A lines = last_error.split("\n")
758N/A if (ind=lines.index("*** Error:")) and (out = lines[ind+1]).present?
758N/A i = ind+2
758N/A while lines[i] and !lines[i].include?("hets: user error") do
out += " "+lines[i]
i+=1
end
msg << out.sub(URI.regexp,"...").sub(/ \/[A-Za-z0-9\/.]*/," ...")
elsif last_error.include?("exited with status")
msg << last_error[0,50]+" ... "+last_error.match("exited with status.*")[0]
else
msg << lines.first
end
end
msg.join(": ")
end
protected
def after_update_state
ontology.state = state
ontology.save!
if ontology.distributed?
ontology.children.update_all(state: ontology.state)
end
end
end