Пример #1
0
def schedule_generation(models):
    generation_id = db.create_generation()
    n_models = len(models)
    model_ids = []
    for strain_id, data in models.items():
        model_ids.append(db.create_model(strain_id, data))

    for (id1, id2) in combinations(model_ids, 2):
        db.create_job(generation_id, id1, id2)

    return generation_id
Пример #2
0
def scan():
    try:
        data = request.get_json()
    except Exception as e:
        return Response(json.dumps({"summary":
                                    "Failed to extract parameters"}),
                        status=400,
                        mimetype='application/json')

    # Extract paramters
    if 'ip_range' not in data:
        return Response(json.dumps({"summary": "Missing IP range"}),
                        status=400,
                        mimetype='application/json')
    if 'start' not in data['ip_range'] or 'end' not in data['ip_range']:
        return Response(json.dumps({"summary": "Missing IP range start/end"}),
                        status=400,
                        mimetype='application/json')
    ip_start = data['ip_range']['start']
    ip_end = data['ip_range']['end']
    exc_ip_start = None
    exc_ip_end = None

    if 'exclude_ips' in data:
        if 'start' not in data['exclude_ips'] or 'end' not in data[
                'exclude_ips']:
            return Response(json.dumps(
                {"summary": "Missing exclude IP start/end"}),
                            status=400,
                            mimetype='application/json')
        exc_ip_start = data['exclude_ips']['start']
        exc_ip_end = data['exclude_ips']['end']

    if 'protocol' not in data:
        return Response(json.dumps({"summary": "Missing protocol list"}),
                        status=400,
                        mimetype='application/json')
    protocols = data['protocol']

    if 'port' not in data:
        return Response(json.dumps({"summary": "Missing port list"}),
                        status=400,
                        mimetype='application/json')
    ports = data['port']

    # Create a new database job entry
    job_id = db.create_job()
    data['job_id'] = job_id

    # Spawn a worker process
    w = multiprocessing.Process(target=worker.spawn_worker, args=(data, ))
    w.daemon = True
    w.start()

    return Response(json.dumps({"job_id": job_id}),
                    status=200,
                    mimetype='application/json')
Пример #3
0
def job_submit():
    body = request.get_json()
    assert "resource_requirements" in body
    assert "code_url" in body

    job = db.create_job(job_spec=body)

    job_schedule_success = schedule_job(job)
    if not job_schedule_success:
        return jsonify(success=False,
                       error_code="NO_DEVICES_ARE_AVAILABLE"), 500

    return jsonify(success=True, job_id=job.id)
Пример #4
0
def add_job():
    try:
        title = request.form['title']
        desc = request.form['description']
        city = request.form['city']
        state = request.form['state']
        zipcode = request.form['zipcode']
        street = request.form['street_address']
        industry = request.form.get('industry')
        due = request.form.get('due_date')

        last = db.create_job(title,
                             desc,
                             street,
                             city,
                             state,
                             zipcode,
                             industry=industry,
                             due_date=due)

        resp = {"status": "success", "id": last[0][0]}
    except Exception as e:
        resp = {"status": "failure", "message": "Could not add job: " + str(e)}
    return jsonify(resp)
Пример #5
0
def submit_job(n_clicks):
    if n_clicks is not None:
        job_id = str(uuid.uuid4())
        db.create_job(job_id, 'queued', 3)
        queue.enqueue(work_and_save, job_id)
    return []