3 クラスタ マシンで celery + rabbitmq をセットアップしました。ファイルのデータに基づいて正規表現を生成し、その情報を使用してテキストを解析するタスクも作成しました。ただし、ファイルの読み取りプロセスは、as タスクの実行ごとではなく、ワーカーのスポーンごとに 1 回だけ実行されることを望みます。
from celery import Celery
celery = Celery('tasks', broker='amqp://localhost//')
import re
@celery.task
def add(x, y):
return x + y
def get_regular_expression():
with open("text") as fp:
data = fp.readlines()
str_re = "|".join([x.split()[2] for x in data ])
return str_re
@celery.task
def analyse_json(tw):
str_re = get_regular_expression()
re.match(str_re,tw.text)
上記のコードでは、ファイルを開き、ワーカーごとに 1 回だけ出力を文字列に読み取り、タスク analyse_json で文字列を使用する必要があります。
どんな助けでも大歓迎です、
ありがとう、アミット