2017-05-10 15 views
1

tasks.py放送タスク:Redisの+セロリ

from celery import Celery 

app = Celery('tasks', 
      broker='redis://localhost', 
      backend='redis://localhost', 
      include=['tasks']) 

app.conf.broker_url = 'redis://localhost:6379/0' 
# Optional configuration, see the application user guide. 
app.conf.update(
    result_expires=3600, 
) 
@app.task 
def add(x, y): 
    return x + y 

私はRedisの(ブローカーとバックエンド)で、すべての労働者に仕事を放送したいと思いますmain.py

from tasks import add 


    if __name__ == '__main__': 
     from celery import Celery 
     app = Celery('tasks', backend='redis://localhost', broker='redis:localhost//') 
     result = add.delay(4, 4) 
     result.ready() 
     value = result.get(timeout=10) 
     print(value) 

とセロリが、私は達成していない、あなたが私を助けることができますか?例えば

+0

申し訳ありませんが動作しません。私はあなたのコメントを理解していない、cあなたはもっと具体的にしてください。 –

+0

あなたは 'tasks.py'に' app'を既に持っていて、あなたは '__main__'に新しいものを作成します。 – stovfl

+1

はい、それは本当です、私はmain.pyの行を必要としません: app = Celery( 'tasks'、バックエンド= 'redis:// localhost'、ブローカー= 'redis:localhost //') –

答えて

0

import tasks 
if __name__ == '__main__': 
    tasks.app.do_something.apply_async(['222'], queue='broadcast_tasks') 
0

私がいることを試してみてください。 main.py

import tasks 
if __name__ == '__main__': 
    result = tasks.add.apply_async(([4, 4]), queue='broadcast_tasks') 
    result.ready() 
    value = result.get() 
    print(value) 

tasks.py

from celery import Celery 
from kombu.common import Broadcast 
app = Celery('tasks', 
      broker='redis://localhost:6379/0', 
      backend='redis://localhost:6379/1', 
      include=['tasks']) 
app.conf.update(
    result_expires=3600, 
) 
task_serializer = 'json' 
result_serializer = 'json' 
accept_content = ['json'] 
timezone = 'UTC' 

app.conf.task_queues = (Broadcast('broadcast_tasks'),) 
app.conf.task_routes = {'tasks.add': {'queue': 'broadcast_tasks'}} 


@app.task 
def add(x, y): 
    return x + y 

をしかし、それは、

+1

誰かが私に答えることができます –

関連する問題