0
我想用Heroku爲我的Django應用程序設置後臺任務。Heroku:使用RQ進行Python的後臺任務
我按照Heroku documentation中說明的步驟操作。 但是,我一開始就陷入了困境。
我已經成功安裝了RQ:
pip install rq
我創建的worker.py
文件,其中包含完全相同的代碼的文件中。
但是,當我嘗試運行:
python worker.py
我得到以下錯誤:
Traceback (most recent call last):
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/client.py", line 572, in execute_command
connection.send_command(*args)
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 439, in connect
sock = self._connect()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 494, in _connect
raise err
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 482, in _connect
sock.connect(socket_address)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "worker.py", line 15, in <module>
worker.work()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/rq/worker.py", line 433, in work
self.register_birth()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/rq/worker.py", line 250, in register_birth
if self.connection.exists(self.key) and \
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/client.py", line 855, in exists
return self.execute_command('EXISTS', name)
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/client.py", line 578, in execute_command
connection.send_command(*args)
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 563, in send_command
self.send_packed_command(self.pack_command(*args))
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 538, in send_packed_command
self.connect()
File "/Users/MyUser/my_app/lib/python3.5/site-packages/redis/connection.py", line 442, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 61 connecting to localhost:6379. Connection refused.
經過一番研究,我意識到,沒有配置。我現在已經安裝了redistogo
,並且在運行heroku config
時我可以找到它。不幸的是,這似乎並不是我做錯的唯一的事情,因爲我仍然遇到同樣的錯誤。
我也嘗試localhost
127.0.0.1
,建議here,但它沒有幫助。
在我發現的所有其他相關問題中,問題不會發生在本地服務器上。
我錯過了哪些步驟?
我以爲這是在我的本地開發環境中運行'pip install rq'完成的......你能告訴我應該如何安裝它,或者如何在本地配置REDISTOGO_URL環境變量? – J0ANMM
好的,我想出了一個辦法:我運行命令'heroku config'而不是''redis:// localhost:6379'時得到'REDISTOGO_URL',它似乎在工作。謝謝! – J0ANMM