mirror of https://github.com/rq/rq.git
Reformat Markdown for Python highlighting.
This commit is contained in:
parent
4d2157cdb5
commit
f3890c85a0
46
README.md
46
README.md
|
@ -10,35 +10,37 @@ easily.
|
|||
|
||||
First, run a Redis server, of course:
|
||||
|
||||
$ redis-server
|
||||
```console
|
||||
$ redis-server
|
||||
```
|
||||
|
||||
To put jobs on queues, you don't have to do anything special, just define
|
||||
your typically lengthy or blocking function:
|
||||
|
||||
```python
|
||||
import requests
|
||||
```python
|
||||
import requests
|
||||
|
||||
def count_words_at_url(url):
|
||||
resp = requests.get(url)
|
||||
return len(resp.text.split())
|
||||
```
|
||||
def count_words_at_url(url):
|
||||
resp = requests.get(url)
|
||||
return len(resp.text.split())
|
||||
```
|
||||
|
||||
You do use the excellent [requests][r] package, don't you?
|
||||
|
||||
Then, create a RQ queue:
|
||||
|
||||
```python
|
||||
from rq import Queue, use_connection
|
||||
use_connection()
|
||||
q = Queue()
|
||||
```
|
||||
```python
|
||||
from rq import Queue, use_connection
|
||||
use_connection()
|
||||
q = Queue()
|
||||
```
|
||||
|
||||
And enqueue the function call:
|
||||
|
||||
```python
|
||||
from my_module import count_words_at_url
|
||||
result = q.enqueue(count_words_at_url, 'http://nvie.com')
|
||||
```
|
||||
```python
|
||||
from my_module import count_words_at_url
|
||||
result = q.enqueue(count_words_at_url, 'http://nvie.com')
|
||||
```
|
||||
|
||||
For a more complete example, refer to the [docs][d]. But this is the essence.
|
||||
|
||||
|
@ -48,11 +50,13 @@ 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
|
||||
from your project's directory:
|
||||
|
||||
$ rqworker
|
||||
*** Listening for work on default
|
||||
Got count_words_at_url('http://nvie.com') from default
|
||||
Job result = 818
|
||||
*** Listening for work on default
|
||||
```console
|
||||
$ rqworker
|
||||
*** Listening for work on default
|
||||
Got count_words_at_url('http://nvie.com') from default
|
||||
Job result = 818
|
||||
*** Listening for work on default
|
||||
```
|
||||
|
||||
That's about it.
|
||||
|
||||
|
|
Loading…
Reference in New Issue