states.rb revision fda87b00b3f144f81547c33512cd397f211b5bba
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase#
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# states:
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * pending
da2294634b553456b3ebb5f5d1ab9dc558b53650Sascha Graef# * fetching
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * processing
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * failed
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * done
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase#
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornbergermodule OntologyVersion::States
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger extend ActiveSupport::Concern
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger include StateUpdater
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
fda87b00b3f144f81547c33512cd397f211b5bbaSascha Graef TERMINAL_STATES = State::TERMINAL_STATES
54b874e5f2464414e09aa63cffa49e236b2a3eafTim Reddehase
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger included do
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase after_save :after_update_state, if: :change_applicable?
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase end
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase def change_applicable?
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase state_changed? &&
29df54c6935a6dc6ebd194518adf1b1a2c19b876Tim Reddehase parent.nil?
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger end
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger def state_message
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger msg = [state]
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger if last_error
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger lines = last_error.split("\n")
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger if (ind=lines.index("*** Error:")) and (out = lines[ind+1]).present?
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger i = ind+2
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger while lines[i] and !lines[i].include?("hets: user error") do
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger out += " "+lines[i]
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger i+=1
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger end
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger msg << out.sub(URI.regexp,"...").sub(/ \/[A-Za-z0-9\/.]*/," ...")
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger elsif last_error.include?("exited with status")
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger msg << last_error[0,50]+" ... "+last_error.match("exited with status.*")[0]
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger else
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger msg << lines.first
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger end
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger end
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger msg.join(": ")
f788f380e8ad6e3923210eaacfc832b2bd015428Julian Kornberger end
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger protected
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
f5a01e37663bdf559d6e251191b5097dd6f28ea5Julian Kornberger def after_update_state
3caef45020e4e733e0385c215b0035a8ef287a04Julian Kornberger ontology.state = state.to_s
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger ontology.save!
0c480325395e8989d1abc5ba6d71a8bdd524bc4eIngo Becker if ontology.distributed?
f5a01e37663bdf559d6e251191b5097dd6f28ea5Julian Kornberger ontology.children.update_all state: ontology.state
0c480325395e8989d1abc5ba6d71a8bdd524bc4eIngo Becker end
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger end
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornbergerend