Created
May 25, 2016 23:08
-
-
Save octosteve/2543f7e16c9e2224ded485b6e17eee0b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def create(%{req_headers: headers, remote_ip: remote_ip, request_path: path, body_params: payload, query_params: query_params} = conn, %{"source" => source }) do | |
Task.async fn -> | |
merged_headers = headers | |
|> add_path(path) | |
|> add_ip(remote_ip) | |
|> Enum.into(%{}) | |
changeset = Event.validate(%Event{}, source, merged_headers, payload, query_params) | |
case Repo.insert(changeset) do | |
{:ok, event} -> | |
event = Map.drop(event, [:__meta__, :__struct__]) | |
Steelbroker.Endpoint.broadcast!("events:all", "new-event", %{response: event}) | |
Repo.all(Subscription) | |
|> Enum.each fn (sub) -> | |
Task.async fn -> | |
HTTPoison.post(sub.url, Poison.encode!(event)) | |
end | |
end | |
end | |
end | |
send_resp(conn, 200, "OK") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment