Rewrite of the connection setup.

I'd want to advice against using `use_connection()` more, as the
connection setup is less explicit, and also pollutes global memory.

Because, well:

    $ python -m this | head -n4 | tail -n1

;)
main
Vincent Driessen 13 years ago
parent 31259fa106
commit 48cee215af

@ -1,10 +1,10 @@
import os import os
import time import time
from rq import Queue, use_connection from rq import Queue, Connection
from fib import slow_fib from fib import slow_fib
# Tell RQ what Redis connection to use
use_connection() def main():
# Range of Fibonacci numbers to compute # Range of Fibonacci numbers to compute
fib_range = range(20, 34) fib_range = range(20, 34)
@ -32,3 +32,9 @@ while not done:
time.sleep(0.2) time.sleep(0.2)
print 'Done' print 'Done'
if __name__ == '__main__':
# Tell RQ what Redis connection to use
with Connection():
main()

@ -1,8 +1,8 @@
from rq import Queue, Worker, use_connection from rq import Queue, Worker, Connection
# Tell rq what Redis connection to use
use_connection()
if __name__ == '__main__': if __name__ == '__main__':
# Tell rq what Redis connection to use
with Connection():
q = Queue() q = Queue()
Worker(q).work() Worker(q).work()

Loading…
Cancel
Save