Skip to content

Instantly share code, notes, and snippets.

@joakimk
Last active Aug 22, 2016
Embed
What would you like to do?
An example of auto reload on deploy in an Elixir Phoenix app
import {Socket} from "phoenix"
let socket = new Socket("/socket", { params: {} })
socket.connect()
let channel = socket.channel("updates", {})
channel.join()
// Reload the app if it's out of date when it joins the websocket
let revision = null
channel.on("welcome", welcome => {
if(!revision) { revision = welcome.revision }
if(revision != welcome.revision) { window.location.reload() }
})
defmodule MyApp.UpdatesChannel do
use Phoenix.Channel
def join(_channel, _message, socket) do
send self, :after_join
{:ok, socket}
end
def handle_info(:after_join, socket) do
# HEROKU_SLUG_COMMIT is available through https://devcenter.heroku.com/articles/dyno-metadata
push socket, "welcome", %{ revision: System.get_env("HEROKU_SLUG_COMMIT") }
{:noreply, socket}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment