示例#1
0
def triggerRelatedItemUpdates(data):
    try:
        ignore_ids = {i['id'] for i in data['ignore']}
        items = Item.query.filter(Item.id.in_(ignore_ids))
        for i in items:
            socketio.emit(
                ITEM_UPDATED, {
                    'type': "item",
                    'target': json.dumps(
                        injectItem.delay(i, item_schema.dump(i)))
                },
                namespace='/admin')
    except Exception as e:
        return
示例#2
0
def setting_listen_update(mapper, connection, target):
    socketio.emit(SETTING_UPDATED, standardize(target), namespace='/admin')
示例#3
0
def setting_listen_insert(mapper, connection, target):
    socketio.emit(SETTING_INSERTED, standardize(target), namespace='/admin')
示例#4
0
def flag_listen_delete(mapper, connection, target):
    print(str(target), str(mapper))
    socketio.emit(FLAG_DELETED,
                  {"target": json.dumps(flag_schema.dump(target))},
                  namespace='/admin')
示例#5
0
def flag_listen_update(mapper, connection, target):
    socketio.emit(FLAG_UPDATED, standardize(target), namespace='/admin')
示例#6
0
def flag_listen_insert(mapper, connection, target):
    socketio.emit(FLAG_INSERTED, standardize(target), namespace='/admin')
示例#7
0
def item_listen_delete(mapper, connection, target):
    print(str(target), str(mapper))
    socketio.emit(ITEM_DELETED, {"target": item_schema.dump(target)},
                  namespace='/admin')
示例#8
0
def item_listen_modify(mapper, connection, target):
    socketio.emit(ITEM_UPDATED, standardize(target), namespace='/admin')
示例#9
0
def item_listen_insert(mapper, connection, target):
    socketio.emit(ITEM_INSERTED, standardize(target), namespace='/admin')
示例#10
0
def annotator_listen_delete(mapper, connection, target):
    print(str(target), str(mapper))
    socketio.emit(ANNOTATOR_DELETED,
                  {"target": json.dumps(annotator_schema.dump(target))},
                  namespace='/admin')
示例#11
0
def annotator_listen_modify(mapper, connection, target):
    socketio.emit(ANNOTATOR_UPDATED, standardize(target), namespace='/admin')
示例#12
0
def annotator_listen_insert(mapper, connection, target):
    socketio.emit(ANNOTATOR_INSERTED, standardize(target), namespace='/admin')
示例#13
0
def admin_api_session():
    setting_stop_queue = Setting.value_of(SETTING_STOP_QUEUE) == SETTING_TRUE
    setting_stop = Setting.value_of(SETTING_CLOSED) == SETTING_TRUE

    affected_annotators = []
    action = None
    key = None

    if request.method == "POST":

        key = request.form['key']
        # hard | soft

        action = request.form['action']

        # Hard shutdown
        if key == 'hard':
            # Close session
            if action == 'close':
                setting_stop = SETTING_TRUE
            # Open session
            elif action == 'open':
                setting_stop = SETTING_FALSE
            else:
                pass

            def tx():
                Setting.set(SETTING_CLOSED, setting_stop)
                db.session.commit()

            with_retries(tx)
        # Soft shutdown (await final judge submission)
        elif key == 'soft':
            annotators = Annotator.query.order_by(Annotator.id).all()
            # Queue shutdown
            if action == 'queue' and not setting_stop:
                setting_stop_queue = SETTING_TRUE

                def tx():
                    for an in annotators:
                        if an.active:
                            an.stop_next = True
                            affected_annotators.append(an.id)
                    db.session.commit()

                with_retries(tx)
            # Dequeue shutdown
            elif action == 'dequeue':
                setting_stop_queue = SETTING_FALSE

                def tx():
                    for an in annotators:
                        if an.active:
                            an.stop_next = False
                            affected_annotators.append(an.id)
                    db.session.commit()

                with_retries(tx)

            else:
                pass

            def tx():
                Setting.set(SETTING_STOP_QUEUE, setting_stop_queue)
                db.session.commit()

            with_retries(tx)

        try:
            socketio.emit(SESSION_UPDATED, {
                'type': "session",
                'target': {
                    "hard_state": setting_stop == SETTING_TRUE,
                    "soft_state": setting_stop_queue == SETTING_TRUE,
                    "action": action,
                    "key": key
                }
            },
                          namespace='/admin')
        except Exception as ignored:
            pass

    return json_response(hard_state=setting_stop,
                         soft_state=setting_stop_queue,
                         action=action,
                         key=key,
                         affected_annotators=affected_annotators)