Aggiunta codice test coda python redis con Python-RQ
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
## Note operative test Python Redis-Queue
|
||||
|
||||
Impiego degli script python x test...
|
||||
|
||||
1) setup preliminare, installando redis + python rq
|
||||
2) chiamare (per fare enqueue) lo script che esegue fuzione python ed accoda task:
|
||||
|
||||
```python
|
||||
python3 rctest.py
|
||||
```
|
||||
|
||||
3) chiamare demone esecuzione (su altro processo, schedulabile) che invoca lo script python rset.py come argomento
|
||||
|
||||
```python
|
||||
rq worker -c rset
|
||||
```
|
||||
Binary file not shown.
@@ -0,0 +1,27 @@
|
||||
from redis import Redis
|
||||
from rq import Queue
|
||||
from wcount import count_words_at_url
|
||||
import time
|
||||
|
||||
#redis_conn = Redis()
|
||||
|
||||
redis_conn = Redis(
|
||||
host='localhost',
|
||||
port=6379,
|
||||
password='24068Seriate')
|
||||
|
||||
q = Queue(connection=redis_conn) # no args implies the default queue
|
||||
|
||||
# Delay execution of count_words_at_url('http://nvie.com')
|
||||
job1 = q.enqueue(count_words_at_url, 'http://nview.com')
|
||||
job2 = q.enqueue(count_words_at_url, 'https://repubblica.it')
|
||||
print('Job1 id: %s' % job1.id)
|
||||
print('Job2 id: %s' % job2.id)
|
||||
|
||||
print(job1.result) # => None # Changed to job.return_value() in RQ >= 1.12.0
|
||||
print(job2.result) # => None # Changed to job.return_value() in RQ >= 1.12.0
|
||||
|
||||
# Now, wait a while, until the worker is finished
|
||||
time.sleep(2)
|
||||
print(job1.result)
|
||||
print(job2.result)
|
||||
@@ -0,0 +1,11 @@
|
||||
#REDIS_URL = 'redis://localhost:6379/1'
|
||||
|
||||
# You can also specify the Redis DB to use
|
||||
REDIS_HOST = 'localhost'
|
||||
REDIS_PORT = 6379
|
||||
REDIS_DB = 0
|
||||
# REDIS_PASSWORD = 'very secret'
|
||||
REDIS_PASSWORD = '24068Seriate'
|
||||
|
||||
# Queues to listen on
|
||||
QUEUES = ['high', 'default', 'low']
|
||||
@@ -0,0 +1,7 @@
|
||||
import requests
|
||||
|
||||
def count_words_at_url(url):
|
||||
resp = requests.get(url)
|
||||
nwords = len(resp.text.split())
|
||||
print ( nwords )
|
||||
return nwords
|
||||
Reference in New Issue
Block a user