diff --git a/app/corpora/events.py b/app/corpora/events.py index f513052e..212af206 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -27,13 +27,13 @@ def recv_query(message): def observe_corpus_analysis_connection(app, corpus_id, session_id): logger = logging.getLogger(__name__) + corpus = Corpus.query.filter_by(id=corpus_id).first() with app.app_context(): - cqi_client = CQiClient(host='172.25.0.2') + cqi_client = CQiClient(host=corpus.analysis_container_ip) while session_id in connected_sessions: logger.warning(cqi_client.ctrl_ping()) logger.warning('Run container, run!') socketio.sleep(3) - corpus = Corpus.query.filter_by(id=corpus_id).first() corpus.status = 'stop analysis' db.session.commit() logger.warning('Stop container, stop!') diff --git a/app/models.py b/app/models.py index c7d5563a..058528ce 100644 --- a/app/models.py +++ b/app/models.py @@ -442,7 +442,8 @@ class Corpus(db.Model): status = db.Column(db.String(16)) title = db.Column(db.String(32)) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) - analysis_ip = db.Column(db.String(16)) + analysis_container_ip = db.Column(db.String(16)) + analysis_container_name = db.Column(db.String(32)) # Relationships files = db.relationship('CorpusFile', backref='corpus', diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index 5362bf38..7c761c3f 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -61,11 +61,14 @@ statusElement.classList.remove(...Object.values(CorpusList.STATUS_COLORS)); statusElement.classList.add(CorpusList.STATUS_COLORS[status] || CorpusList.STATUS_COLORS['default']); statusElement.innerText = status; - if (status === 'prepared' || status === 'start analysis' || status === 'analysing') { - var analyseBtn = document.getElementById('analyse'); + var analyseBtn = document.getElementById('analyse'); + if (status === 'prepared') { + analyseBtn.classList.remove('hide', 'disabled'); + } else if (status === 'analysing' || status === 'start analysis' || status === 'stop analysis') { analyseBtn.classList.remove('hide'); + analyseBtn.classList.add('disabled'); } - if (status === 'prepared' || status === 'start analysis' || status === 'analysing') { + if (status === 'prepared' || status === 'start analysis' || status === 'analysing' || status === 'stop analysis') { var prepareBtn = document.getElementById('prepare'); prepareBtn.classList.add('hide'); } diff --git a/migrations/versions/776761fb7466_.py b/migrations/versions/776761fb7466_.py new file mode 100644 index 00000000..3106d5bd --- /dev/null +++ b/migrations/versions/776761fb7466_.py @@ -0,0 +1,32 @@ +"""empty message + +Revision ID: 776761fb7466 +Revises: 0aa38a7973c5 +Create Date: 2019-11-07 08:34:01.676055 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '776761fb7466' +down_revision = '0aa38a7973c5' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('corpora', sa.Column('analysis_container_ip', sa.String(length=16), nullable=True)) + op.add_column('corpora', sa.Column('analysis_container_name', sa.String(length=32), nullable=True)) + op.drop_column('corpora', 'analysis_ip') + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('corpora', sa.Column('analysis_ip', sa.VARCHAR(length=16), autoincrement=False, nullable=True)) + op.drop_column('corpora', 'analysis_container_name') + op.drop_column('corpora', 'analysis_container_ip') + # ### end Alembic commands ###