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:
|
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
|
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:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
def count_words_at_url(url):
|
def count_words_at_url(url):
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
return len(resp.text.split())
|
return len(resp.text.split())
|
||||||
```
|
```
|
||||||
|
|
||||||
You do use the excellent [requests][r] package, don't you?
|
You do use the excellent [requests][r] package, don't you?
|
||||||
|
|
||||||
Then, create a RQ queue:
|
Then, create a RQ queue:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from rq import Queue, use_connection
|
from rq import Queue, use_connection
|
||||||
use_connection()
|
use_connection()
|
||||||
q = Queue()
|
q = Queue()
|
||||||
```
|
```
|
||||||
|
|
||||||
And enqueue the function call:
|
And enqueue the function call:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from my_module import count_words_at_url
|
from my_module import count_words_at_url
|
||||||
result = q.enqueue(count_words_at_url, 'http://nvie.com')
|
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.
|
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
|
To start executing enqueued function calls in the background, start a worker
|
||||||
from your project's directory:
|
from your project's directory:
|
||||||
|
|
||||||
$ rqworker
|
```console
|
||||||
*** Listening for work on default
|
$ rqworker
|
||||||
Got count_words_at_url('http://nvie.com') from default
|
*** Listening for work on default
|
||||||
Job result = 818
|
Got count_words_at_url('http://nvie.com') from default
|
||||||
*** Listening for work on default
|
Job result = 818
|
||||||
|
*** Listening for work on default
|
||||||
|
```
|
||||||
|
|
||||||
That's about it.
|
That's about it.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue