示例#1
0
        workers[worker.hostname] = {"id": worker.id,
                                    "hostname": worker.hostname,
                                    "status": worker.status,
                                    "connection": worker.connection,
                                    "system": worker.system,
                                    "ip_address": worker.ip_address}

    """
    This is a temporary solution for saving the workers connections:
    we read them from the workers dict we just created and build an
    update query for each one of them. It seems not possible to save
    the objects on the fly in the Workers.select() loop above.
    """

    for k, v in workers.iteritems():
        worker = Worker.query.get(v['id'])
        worker.connection = v['connection']
        db.session.add(worker)
        db.session.commit()

    return jsonify(workers)

@workers.route('/update', methods=['POST'])
def workers_update():
    status = request.form['status']
    # TODO parse
    workers_ids = request.form['id']
    workers_list = list_integers_string(workers_ids)
    for worker_id in workers_list:
        print("updating worker %s = %s " % (worker_id, status))