Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 2022 #183

Merged
merged 6 commits into from
Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on: [push, pull_request]

jobs:
format:
name: Format and compile with warnings as errors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.1

- name: Install OTP and Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: 24.0
elixir-version: 1.13.4

- name: Install dependencies
run: mix deps.get

- name: Run "mix format"
run: mix format --check-formatted

- name: Compile with --warnings-as-errors
run: mix compile --warnings-as-errors

test:
name: Test (Elixir ${{matrix.elixir}} | Erlang/OTP ${{matrix.otp}})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- otp: 24.0
elixir: 1.13.4
coverage: true
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v2

- name: Install OTP and Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Install dependencies
run: mix deps.get --only test

- name: Run tests
run: mix test --trace

dialyzer:
name: Dialyzer (Elixir ${{matrix.elixir}} | Erlang/OTP ${{matrix.otp}})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- otp: 24.0
elixir: 1.13.4
steps:
- uses: actions/checkout@v2

- name: Install OTP and Elixir
uses: erlef/setup-elixir@v1
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}

- name: Install dependencies
run: mix deps.get

- name: Restore PLT cache
uses: actions/cache@v2
id: plt_cache
with:
key: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
restore-keys: |
${{ runner.os }}-${{ steps.beam.outputs.elixir-version }}-${{ steps.beam.outputs.otp-version }}-plt
path: |
priv/plts

# Create PLTs if no cache was found
- name: Create PLTs
if: steps.plt_cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

- name: Run dialyzer
run: mix dialyzer
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ erl_crash.dump
/log
/docs
/rel/poxa
.local.plt
# idea plugin
/.idea
poxa.iml
# vscode plugin
/.elixir_ls
priv/plts
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

11 changes: 7 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import Config
if Mix.env == :test do
config :logger, backends: []
end

import System

if config_env() == :test do
# Capture all logs
config :logger, level: :debug
# ... but only alert and up show on the console
config :logger, :console, level: :alert
end

config :poxa,
port: get_env("PORT", "8080") |> String.to_integer(),
app_key: get_env("POXA_APP_KEY", "app_key"),
Expand Down
11 changes: 11 additions & 0 deletions lib/poxa/adapter/gproc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@ defmodule Poxa.Adapter.GProc do
import :gproc
require Ex2ms

@impl true
def register!(key) do
reg({:p, :l, {:pusher, key}})
end

@impl true
def register!(key, value) do
reg({:p, :l, {:pusher, key}}, value)
end

@impl true
def unregister!(key) do
unreg({:p, :l, {:pusher, key}})
end

@impl true
def send!(message, channel, sender) do
:gproc.send({:p, :l, {:pusher, channel}}, {sender, message})
end

@impl true
def send!(message, channel, sender, socket_id) do
:gproc.send({:p, :l, {:pusher, channel}}, {sender, message, socket_id})
end

@impl true
def subscription_count(channel, pid \\ :_)

def subscription_count(channel, pid) when is_pid(pid) or pid == :_ do
Expand All @@ -44,13 +50,15 @@ defmodule Poxa.Adapter.GProc do
|> select_count
end

@impl true
def subscriptions(pid) do
Ex2ms.fun do
{{:p, :l, {:pusher, channel}}, ^pid, {user_id, _}} -> [channel, user_id]
end
|> select
end

@impl true
def channels(pid \\ :_) do
Ex2ms.fun do
{{:p, :l, {:pusher, channel}}, ^pid, _} -> channel
Expand All @@ -59,15 +67,18 @@ defmodule Poxa.Adapter.GProc do
|> Enum.uniq_by(& &1)
end

@impl true
def unique_subscriptions(channel) do
for {_pid, {user_id, user_info}} <- lookup_values({:p, :l, {:pusher, channel}}), into: %{} do
{user_id, user_info}
end
end

@impl true
def fetch(key) do
get_value({:p, :l, {:pusher, key}})
end

@impl true
def clean_up, do: goodbye()
end
2 changes: 1 addition & 1 deletion lib/poxa/crypto_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Poxa.CryptoHelper do
"""
@spec hmac256_to_string(binary, binary) :: binary
def hmac256_to_string(app_secret, to_sign) do
:crypto.hmac(:sha256, app_secret, to_sign) |> Base.encode16(case: :lower)
:crypto.mac(:hmac, :sha256, app_secret, to_sign) |> Base.encode16(case: :lower)
end

@doc """
Expand Down
2 changes: 0 additions & 2 deletions lib/poxa/pusher_event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ defmodule Poxa.PusherEvent do
(!socket_id || Poxa.SocketId.valid?(socket_id))
end

defp valid?(_), do: false

@doc """
Send `message` to `channels` excluding `exclude`
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/poxa/registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule Poxa.Registry do
@doc """
Returns the unique subscriptions of the given channel.
"""
@callback unique_subscriptions(binary) :: Map.t()
@callback unique_subscriptions(binary) :: map

@doc """
Returns the value assigned with the given property.
Expand Down
2 changes: 1 addition & 1 deletion lib/poxa/subscription_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Poxa.SubscriptionHandler do
import Poxa.Event, only: [notify: 2]

@doc false
def start_link(), do: GenServer.start_link(__MODULE__, [])
def start_link(_), do: GenServer.start_link(__MODULE__, [])

@doc false
def init(_) do
Expand Down
6 changes: 3 additions & 3 deletions lib/poxa/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ defmodule Poxa.Supervisor do
@doc false
def init([]) do
{:ok, web_hook} = Application.fetch_env(:poxa, :web_hook)
subscription_worker = worker(Poxa.SubscriptionHandler, [])
subscription_worker = Poxa.SubscriptionHandler

children =
if to_string(web_hook) != "" do
web_wook_supervisor = worker(Poxa.WebHook.Supervisor, [])
web_wook_supervisor = Poxa.WebHook.Supervisor
[subscription_worker, web_wook_supervisor]
else
[subscription_worker]
end

supervise(children, strategy: :one_for_one)
Supervisor.init(children, strategy: :one_for_one)
end
end
2 changes: 1 addition & 1 deletion lib/poxa/web_hook/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Poxa.WebHook.Dispatcher do
@timeout 1500

@doc false
def start_link do
def start_link(_) do
GenServer.start_link(__MODULE__, nil)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/poxa/web_hook/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Poxa.WebHook.Handler do
@delay 1500

@doc false
def start_link(), do: GenServer.start_link(__MODULE__, [])
def start_link(_), do: GenServer.start_link(__MODULE__, [])

@doc false
def init(_) do
Expand Down
8 changes: 3 additions & 5 deletions lib/poxa/web_hook/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ defmodule Poxa.WebHook.Supervisor do
use Supervisor

@doc false
def start_link do
def start_link(_) do
Supervisor.start_link(__MODULE__, [])
end

@doc """
This supervisor will spawn a `Watcher` to monitor a handler for web hook events and a `GenServer` to dispatch the actual requests.
"""
def init([]) do
web_wook_dispatcher = worker(Poxa.WebHook.Dispatcher, [])
web_wook_handler = worker(Poxa.WebHook.Handler, [])
children = [web_wook_handler, web_wook_dispatcher]
children = [Poxa.WebHook.Dispatcher, Poxa.WebHook.Handler]

supervise(children, strategy: :one_for_one)
Supervisor.init(children, strategy: :one_for_one)
end
end
17 changes: 6 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ defmodule Poxa.Mixfile do
def project do
[
app: :poxa,
version: "1.1.2",
version: "1.2.0",
name: "Poxa",
elixir: "~> 1.9",
elixir: "~> 1.13",
deps: deps(),
dialyzer: [
plt_add_apps: ~w(cowboy poison gproc httpoison signaturex),
plt_file: ".local.plt",
flags:
~w(-Wunmatched_returns -Werror_handling -Wrace_conditions -Wno_opaque --fullpath --statistics)
]
dialyzer: [plt_file: {:no_warn, "priv/plts/dialyzer.plt"}]
]
end

Expand All @@ -27,11 +22,11 @@ defmodule Poxa.Mixfile do
{:jason, "~> 1.0"},
{:signaturex, "~> 1.3"},
{:gproc, "~> 0.8"},
{:mimic, "~> 1.0", only: :test},
{:pusher, "~> 2.1", only: :test},
{:httpoison, "~> 1.0"},
{:ex2ms, "~> 1.5"},
{:dialyxir, "~> 1.0", only: [:dev, :test]}
{:mimic, "~> 1.0", only: :test},
{:pusher, "~> 2.1", only: :test},
{:dialyxir, "~> 1.0", only: :dev, runtime: false}
]
end
end
Loading