states.rb revision ee5342a8882c2fc7631fcffb5497e6597747887c
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase#
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# states:
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * pending
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger# * downloading
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
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger included do
f5a01e37663bdf559d6e251191b5097dd6f28ea5Julian Kornberger after_save :after_update_state, if: :state_changed?
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