django-gearman-commands 0.6.1
關於Gearman
client客戶端:需要完成的job,這是一個web應用。
server服務端:接收job並提交給workers處理。
worker作業端:詢問是否有job,並處理job。worker可獨立執行任務。
生產環境中,最好有兩個worker來確保高可用。
為什麼要使用 django-gearman-commands?
django-gearman-commands解決的主要問題是編寫worker,為你的Django APP 使用。
django-gearman-commands 提供了什麼?
為你的worker是提供基礎的類
GearmanWorkerBaseCommand可以代替哪些低階的API
提交任務更簡單
gearman_submit_job 命令 可以提交新的任務到gearmand,不用自己編寫worker,也不用使用manage.py的提交命令。
開搞
安裝
你肯定現有一個Django的應用,並希望安裝Django-gearman-commands,這是一個標準的Django應用程式,但他不提供任何的models,views和urls,他只包含少數的類,自定義管理命令和測試
只有一個新的依賴項新增到你的應用程式中,python-gearman API:
$ pip install -e git+https://github.com/Yelp/python-gearman.git@2ed9d88941e31e3358a0b80787254d0c2cfaa78a#egg=gearman-dev
另外有一個可選的依賴項,用來輸出更好看的服務端資訊。
$ pip install prettytable==0.5
最後新增django-gearman-commands 到你的setting的INSTALL中
INSTALLED_APPS = ( # ...installed apps... 'django_gearman_commands', )
以及gearman的服務端配置
GEARMAN_SERVERS = ['127.0.0.1:4730']