diff --git a/IOB-PI/test-python-rq/README.md b/IOB-PI/test-python-rq/README.md new file mode 100644 index 0000000..ed0c3b7 --- /dev/null +++ b/IOB-PI/test-python-rq/README.md @@ -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 + ``` diff --git a/IOB-PI/test-python-rq/README.pdf b/IOB-PI/test-python-rq/README.pdf new file mode 100644 index 0000000..ae9ba34 Binary files /dev/null and b/IOB-PI/test-python-rq/README.pdf differ diff --git a/IOB-PI/test-python-rq/rctest.py b/IOB-PI/test-python-rq/rctest.py new file mode 100644 index 0000000..467b222 --- /dev/null +++ b/IOB-PI/test-python-rq/rctest.py @@ -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) \ No newline at end of file diff --git a/IOB-PI/test-python-rq/rset.py b/IOB-PI/test-python-rq/rset.py new file mode 100644 index 0000000..cc28a73 --- /dev/null +++ b/IOB-PI/test-python-rq/rset.py @@ -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'] \ No newline at end of file diff --git a/IOB-PI/test-python-rq/wcount.py b/IOB-PI/test-python-rq/wcount.py new file mode 100644 index 0000000..ce4cee5 --- /dev/null +++ b/IOB-PI/test-python-rq/wcount.py @@ -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 \ No newline at end of file