Skip to content

Instantly share code, notes, and snippets.

@lushiyun
Created September 26, 2020 18:21
Show Gist options
  • Save lushiyun/bde6237261813c6c8bc627eaf86ab128 to your computer and use it in GitHub Desktop.
Save lushiyun/bde6237261813c6c8bc627eaf86ab128 to your computer and use it in GitHub Desktop.
# 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