|
|
@ -12,14 +12,11 @@ and it is extremely simple to use.
|
|
|
|
|
|
|
|
|
|
|
|
First, run a Redis server, of course:
|
|
|
|
First, run a Redis server, of course:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight console %}
|
|
|
|
|
|
|
|
$ redis-server
|
|
|
|
$ redis-server
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
To put jobs on queues, you don't have to do anything special, just define
|
|
|
|
To put jobs on queues, you don't have to do anything special, just define
|
|
|
|
your typically lengthy or blocking function:
|
|
|
|
your typically lengthy or blocking function:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight python %}
|
|
|
|
|
|
|
|
import urllib2
|
|
|
|
import urllib2
|
|
|
|
|
|
|
|
|
|
|
|
def count_words_at_url(url):
|
|
|
|
def count_words_at_url(url):
|
|
|
@ -31,23 +28,17 @@ def count_words_at_url(url):
|
|
|
|
break
|
|
|
|
break
|
|
|
|
count += len(line.split())
|
|
|
|
count += len(line.split())
|
|
|
|
return count
|
|
|
|
return count
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Then, create a RQ queue:
|
|
|
|
Then, create a RQ queue:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight python %}
|
|
|
|
|
|
|
|
import rq import *
|
|
|
|
import rq import *
|
|
|
|
use_redis()
|
|
|
|
use_redis()
|
|
|
|
q = Queue()
|
|
|
|
q = Queue()
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
And enqueue the function call:
|
|
|
|
And enqueue the function call:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight python %}
|
|
|
|
|
|
|
|
from my_module import count_words_at_url
|
|
|
|
from my_module import count_words_at_url
|
|
|
|
result = q.enqueue(
|
|
|
|
result = q.enqueue(count_words_at_url, 'http://nvie.com')
|
|
|
|
count_words_at_url, 'http://nvie.com')
|
|
|
|
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For a more complete example, refer to the [docs][d]. But this is the essence.
|
|
|
|
For a more complete example, refer to the [docs][d]. But this is the essence.
|
|
|
|
|
|
|
|
|
|
|
@ -59,13 +50,11 @@ For a more complete example, refer to the [docs][d]. But this is the essence.
|
|
|
|
To start executing enqueued function calls in the background, start a worker
|
|
|
|
To start executing enqueued function calls in the background, start a worker
|
|
|
|
from your project's directory:
|
|
|
|
from your project's directory:
|
|
|
|
|
|
|
|
|
|
|
|
{% highlight console %}
|
|
|
|
|
|
|
|
$ rqworker
|
|
|
|
$ rqworker
|
|
|
|
*** Listening for work on default
|
|
|
|
*** Listening for work on default
|
|
|
|
Got count_words_at_url('http://nvie.com') from default
|
|
|
|
Got count_words_at_url('http://nvie.com') from default
|
|
|
|
Job result = 818
|
|
|
|
Job result = 818
|
|
|
|
*** Listening for work on default
|
|
|
|
*** Listening for work on default
|
|
|
|
{% endhighlight %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
That's about it.
|
|
|
|
That's about it.
|
|
|
|
|
|
|
|
|
|
|
|