簡體   English   中英

使用Celery(python)和RabbitMQ將任務結果保存到特定文件位置?

[英]Using Celery (python) & RabbitMQ to save results of tasks to a specific file location?

大家好,我正在為學校的一個項目設計原型(我是研究助理,所以這不是一個分級項目)。 我在已經設置並正在運行的服務器群集(具有48個工作人員/核心)上運行celery。 我的項目簡而言之是,我們想使用celery對大量文件/任務進行一些數字處理。

因此,將結果保存到實際文件中非常重要,我們有大量的數據,並且在運行傳統的任務隊列/后端時,它不會放入RAM。

無論如何...我的原型(具有微不足道的添加功能):

task.py

from celery import Celery

app=Celery()

@app.task
def mult(x,y):
    return x*y

這在我執行時效果很好: $ celery worker -A task -l info

但是,如果我嘗試添加新的后端:

from celery import Celery

app=Celery()
app.conf.update(CELERY_RESULT_BACKEND = 'file://~/Documents/results')
@app.task
def mult(x,y):
    return x*y

我收到一個相當大的錯誤:

[2017-08-04 13:22:18,133: CRITICAL/MainProcess] Unrecoverable error: 
AttributeError("'NoneType' object has no attribute 'encode'",)
Traceback (most recent call last):
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'backend'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bartolucci/anaconda3/lib/python3.6/site-        packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/bootsteps.py", line 115, in start
self.on_start()
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/apps/worker.py", line 143, in on_start
self.emit_banner()
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/apps/worker.py", line 158, in emit_banner
' \n', self.startup_info(artlines=not use_image))),
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/apps/worker.py", line 221, in startup_info
results=self.app.backend.as_uri(),
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/kombu/utils/objects.py", line 44, in __get__
value = obj.__dict__[self.__name__] = self.__get(obj)
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/app/base.py", line 1183, in backend
return self._get_backend()
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/app/base.py", line 902, in _get_backend
return backend(app=self, url=url)
  File "/home/bartolucci/anaconda3/lib/python3.6/site-packages/celery/backends/filesystem.py", line 45, in __init__
self.path = path.encode(encoding)
AttributeError: 'NoneType' object has no attribute 'encode'

我只參加了2天的項目,之前從未使用過芹菜(或類似的圖書館)(我來自籬笆的算法和數學方面)。 我目前正在處理celery的用戶指南文檔,但是老實說,他們在這個細節上非常稀疏。

非常感謝您的幫助。

在此處查看文件系統支持的結果后台的celery代碼。 https://github.com/celery/celery/blob/master/celery/backends/filesystem.py#L54

您的路徑必須以file:///(3個斜杠)開頭。您的設置將其以file://(2個斜杠)開頭。

您可能還想使用絕對路徑而不是〜。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM