summaryrefslogtreecommitdiff
path: root/rq/scripts/rqgenload.py
blob: b643c49d1d30169d66a0ffa08c73dd14b22cc15b (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
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import optparse
from rq import use_connection, Queue
from rq import dummy


def parse_args():
    parser = optparse.OptionParser()
    parser.add_option('-n', '--count', type='int', dest='count', default=1)
    opts, args = parser.parse_args()
    return (opts, args, parser)

def main():
    import sys
    sys.path.insert(0, '.')

    opts, args, parser = parse_args()

    use_connection()

    queues = ('default', 'high', 'low')

    sample_calls = [
            (dummy.do_nothing, [], {}),
            (dummy.sleep, [1], {}),
            (dummy.fib, [8], {}),              # normal result
            (dummy.fib, [24], {}),             # takes pretty long
            (dummy.div_by_zero, [], {}),       # 5 / 0 => div by zero exc
            (dummy.random_failure, [], {}),    # simulate random failure (handy for requeue testing)
    ]

    for i in range(opts.count):
        import random
        f, args, kwargs = random.choice(sample_calls)

        q = Queue(random.choice(queues))
        q.enqueue(f, *args, **kwargs)

        #q = Queue('foo')
        #q.enqueue(do_nothing)
        #q.enqueue(sleep, 3)
        #q = Queue('bar')
        #q.enqueue(yield_stuff)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)
        #q.enqueue(do_nothing)

if __name__ == '__main__':
    main()