summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorVincent Driessen <vincent@3rdcloud.com>2011-11-15 00:35:18 +0100
committerVincent Driessen <vincent@3rdcloud.com>2011-11-15 00:35:18 +0100
commitcd31f6aba9b498ea56c62158aee4c8db4062e82c (patch)
tree4668a54c22964c102a1c123b8041511ed7b1c2db /examples
parent56fc74118e97b069aac14c94b6216b334497098b (diff)
downloadrq-cd31f6aba9b498ea56c62158aee4c8db4062e82c.tar.gz
Adapt examples so they run again.
Remove sync part of the example.
Diffstat (limited to 'examples')
-rw-r--r--examples/run_example.py52
-rw-r--r--examples/run_worker.py8
2 files changed, 28 insertions, 32 deletions
diff --git a/examples/run_example.py b/examples/run_example.py
index 00ab391..f3414d3 100644
--- a/examples/run_example.py
+++ b/examples/run_example.py
@@ -1,37 +1,31 @@
import os
import time
-from rq import push_connection
+from rq import conn
from redis import Redis
from fib import slow_fib
-push_connection(Redis())
+# Tell rq what Redis connection to use
+conn.push(Redis())
-sync = False
-if sync:
- print 'Synchronously:'
- for x in range(22, 33):
- print 'fib(%d) = %d' % (x, slow_fib(x))
- print 'Done'
-else:
- # Kick off the tasks asynchronously
- async_results = {}
- for x in range(22, 33):
- async_results[x] = slow_fib.delay(x)
+# Kick off the tasks asynchronously
+async_results = {}
+for x in range(20, 30):
+ async_results[x] = slow_fib.delay(x)
- done = False
- while not done:
- os.system('clear')
- print 'Asynchronously: (now = %s)' % time.time()
- done = True
- for x in range(22, 33):
- result = async_results[x].return_value
- if result is None:
- done = False
- result = '(calculating)'
- print 'fib(%d) = %s' % (x, result)
- print ''
- print 'To start the actual in the background, run a worker:'
- print ' python examples/run_worker.py'
- time.sleep(1)
+done = False
+while not done:
+ os.system('clear')
+ print 'Asynchronously: (now = %s)' % time.time()
+ done = True
+ for x in range(20, 30):
+ result = async_results[x].return_value
+ if result is None:
+ done = False
+ result = '(calculating)'
+ print 'fib(%d) = %s' % (x, result)
+ print ''
+ print 'To start the actual in the background, run a worker:'
+ print ' python examples/run_worker.py'
+ time.sleep(1)
- print 'Done'
+print 'Done'
diff --git a/examples/run_worker.py b/examples/run_worker.py
index 6be28b9..3efc472 100644
--- a/examples/run_worker.py
+++ b/examples/run_worker.py
@@ -1,7 +1,9 @@
from redis import Redis
-from rq import push_connection
+from rq import conn
from rq.daemon import run_daemon
-push_connection(Redis())
+# Tell rq what Redis connection to use
+conn.push(Redis())
-run_daemon(['default'])
+listen_on_queues = ['default']
+run_daemon(listen_on_queues)