Created
September 26, 2020 18:21
-
-
Save lushiyun/bde6237261813c6c8bc627eaf86ab128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/channels/messages_channel.rb | |
class MessagesChannel < ApplicationCable::Channel | |
... | |
def receive(data) | |
... | |
MessageRelayJob.perform_later(message) | |
end | |
... | |
end | |
# app/jobs/message_relay_job.rb | |
class MessageRelayJob < ApplicationJob | |
queue_as :default | |
def perform(message) | |
team = message.team | |
MessagesChannel.broadcast_to(team, MessageSerializer.new(message).serialized_json) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment