2016-08-16 7 views
2

私は基本的なチャットルームの実装についてDHHのチュートリアルに従っています。ActiveJobとSidekiqがActionCableチャットルームで働いている

ActiveJobコンポーネントを試して統合するまで、実装は十分に機能します。

私のレールやサイドキックコンソールにエラーメッセージが表示されません。しかし、_メッセージ部分はただレンダリングされていません。 ActiveJobメソッドにbinding.pryを置くと、すべての要素がうまくいくように見えるので、それはジョブの実行と関係があると思いますか?私はroom_channel.rbから

ActionCable.server.broadcast('room_channel', message: data['message']) 

を呼ぶそれだけで正常に動作したときに

はさらに、この疑惑をサポートするために!

私はこれに数時間を費やしており、さらにデバッグする方法を考えることはできません。私はそれが動作するようにSidekiqとのredis設定を必要としているのだろうかと思っています。私は、これまでにちょうど入れている:application.rb

config.active_job.queue_adapter = :sidekiq 

私もRedisの初期化子を持っている必要がありますか?

その意見や他の洞察についてのご意見は大変ありがとうございます。

Railsのサーバー:

// ♥ rails s 
=> Booting Puma 
=> Rails 5.0.0.1 application starting in development on  http://localhost:3000 
=> Run `rails server -h` for more startup options 
Puma starting in single mode... 
* Version 3.6.0 (ruby 2.2.3-p173), codename: Sleepy Sunday Serenity 
* Min threads: 5, max threads: 5 
* Environment: development 
* Listening on tcp://localhost:3000 
Use Ctrl-C to stop 
Started GET "/cable" for ::1 at 2016-08-16 16:25:21 +0100  
    ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations" 
Started GET "/cable/" [WebSocket] for ::1 at 2016-08-16 16:25:21 +0100 
Successfully upgraded to WebSocket (REQUEST_METHOD: GET,  HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 
Finished "/cable/" [WebSocket] for ::1 at 2016-08-16 16:25:21 +0100 
Started GET "/cable" for ::1 at 2016-08-16 16:25:22 +0100 
Started GET "/cable/" [WebSocket] for ::1 at 2016-08-16 16:25:22 +0100 
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket) 
RoomChannel is transmitting the subscription confirmation 
RoomChannel is streaming from room_channel 
RoomChannel#speak({"message"=>"new message"}) 
    (0.1ms) BEGIN 
     SQL (0.5ms) INSERT INTO "messages" ("content", "created_at",  "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["content", "new  message"], ["created_at", 2016-08-16 15:25:25 UTC], ["updated_at", 2016- 08-16 15:25:25 UTC]] 
(1.3ms) COMMIT 
[ActiveJob] Enqueued MessageBroadcastJob (Job ID: 5981c48d-afbc-4fad-a595-198b56aa90f4) to Sidekiq(default) with arguments: #<GlobalID:0x007f82aa837b90 @uri=#<URI::GID gid://dragonfly/Message/39>> 

Sidekiq:

bundle exec sidekiq -q default -q mailers 

2016-08-16T15:23:32.583Z 70743 TID-ow892ejts INFO: Running in ruby  2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15] 
2016-08-16T15:23:32.583Z 70743 TID-ow892ejts INFO: See LICENSE and the LGPL-3.0 for licensing details. 
2016-08-16T15:23:32.583Z 70743 TID-ow892ejts INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org 
2016-08-16T15:23:32.584Z 70743 TID-ow892ejts INFO: Booting Sidekiq 4.1.2 with redis options {:url=>nil} 
2016-08-16T15:23:32.587Z 70743 TID-ow892ejts INFO: Starting processing, hit Ctrl-C to stop 
2016-08-16T15:24:00.652Z 70743 TID-ow89s527k MessageBroadcastJob JID-4ae621ca049eb428ced1c7d2 INFO: start 
2016-08-16T15:24:01.153Z 70743 TID-ow89s527k MessageBroadcastJob JID- 4ae621ca049eb428ced1c7d2 INFO: done: 0.501 sec 
2016-08-16T15:24:14.351Z 70743 TID-ow89s52rk MessageBroadcastJob JID-fe94b25a9100e83f874ea785 INFO: start 

アプリ/仕事/ message_broadcast_job.rb

class MessageBroadcastJob < ApplicationJob 
     queue_as :default 

     def perform(message) 
     ActionCable.server.broadcast "room_channel", {message: render_message(message)} 
    end 

    private 

    def render_message(message) 
    ApplicationController.renderer.render(partial: 'messages/message', locals: { message: message }) 
    end 

end 

アプリ/資産/ JavaScriptの/チャンネル/ room.coffee

App.room = App.cable.subscriptions.create "RoomChannel", 
    connected: -> 
    # Called when the subscription is ready for use on the server 

    disconnected: -> 
    # Called when the subscription has been terminated by the server 

    received: (data) -> 
    alert data['message'] 

    speak: (message) -> 
    @perform 'speak', message: message 

$(document).on 'keypress', '[data-behaviour~=room_speaker]', (event) -> 
    if event.keyCode is 13 
    App.room.speak event.target.value 
    event.target.value = '' 
    event.preventDefault() 
+0

あなたはsidekiqでactioncableを使用することでこれまで進歩しましたか? –

答えて

0

ActiveJobまたはSidekiqとは関係ありません。私は、部分をレンダリングするときにいくつかのエラーがあるはずです。

がうまくいけば、あなたがそのような未定義のメソッドまたはのようなものなど、いくつかの意味のエラーを取得し、Railsのコンソールで行を実行

ApplicationController.renderer.render(partial: 'messages/message', locals: { message: message }) 

を試してみてください。

+1

ありがとう!この種のものをデバッグするための良いアイデア。だから私はRailsのエキスパートにこれについて尋ね、彼らは一日それをハッキングし、彼らはAction Cableへの制御権を譲り渡さないという点で、Sidekiq(または任意のキューイングサービス)の問題であると結論づけました。 –

関連する問題