バックグラウンドで Wisper pub/sub を使用する単純な POST Grape エンドポイントがあります。
module Something
class Doit < Grape::API
post :now do
service = SomePub.new
service.subscribe(SomeSub.new)
service.call(params)
end
end
end
実際に計算が行われるSomeSub
場所は次のとおりです。
class SomeSub
def do_calculations(payload)
{result: "42"}.to_json
end
end
SomePub
も簡単です:
class SomePub
include Wisper::Publisher
def call(payload)
broadcast(:do_calculations, payload)
end
end
したがって{result: "42"}
、Grape のpost :now
エンドポイントを呼び出すときに JSON で応答する必要があります。
残念ながら、この方法では機能しません。私が持っているものは次のとおりです。
{"local_registrations":[{"listener":{},"on":{},"with":null,"prefix":"","allowed_classes":[],"broadcaster":{}}]}
Wisper の wiki の例はあまり役に立ちません ( https://github.com/krisleech/wisper/wiki/Grape )
SomePub#do_calculations
Grape のエンドポイント呼び出しの結果として、実際に結果を渡す方法はありますか?