summaryrefslogtreecommitdiff
path: root/tests/queue.py
blob: 3947dbd6d02561d038db4c518bb80064f3032a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# uwsgi --queue 10 --queue-store test.queue --master --module tests.queue --socket :3031

import uwsgi
import os
from flask import Flask, render_template, request, redirect, flash

app = Flask(__name__)
app.debug = True
app.secret_key = os.urandom(24)


@app.route('/')
def index():
    return render_template('queue.html', uwsgi=uwsgi)


@app.route('/push', methods=['POST'])
def push_item():
    if uwsgi.queue_push(request.form['body']):
        flash('item enqueued')
        return redirect('/')
    else:
        flash('unable to enqueue item')
        return render_template('queue.html', uwsgi=uwsgi)


@app.route('/get', methods=['POST'])
def get_item():
    flash("slot %s value = %s" % (request.form['slot'], uwsgi.queue_get(int(request.form['slot']))))
    return redirect('/')


@app.route('/pop', methods=['POST'])
def pop_item():
    flash("popped value = %s" % uwsgi.queue_pop())
    return redirect('/')


@app.route('/pull', methods=['POST'])
def pull_item():
    flash("pulled value = %s" % uwsgi.queue_pull())
    return redirect('/')


@app.route('/set', methods=['POST'])
def set_item():
    if uwsgi.queue_set(int(request.form['pos']), request.form['body']):
        flash('item set')
        return redirect('/')
    else:
        flash('unable to set item')
        return render_template('queue.html', uwsgi=uwsgi)