Skip to content
Open
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
60 changes: 60 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Yggdrasil for PostgreSQL Checks

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
MIX_ENV: test

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DATABASE: postgres
ports:
- 5432/tcp

strategy:
matrix:
elixir: [1.12.2]
otp: [24.0.3]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-elixir@v1
name: "Setup Elixir"
with:
experimental-otp: true
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
- uses: actions/cache@v1
name: "Retrieves cached PLT"
id: plt-cache
with:
path: priv/plts
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
- name: "Get dependencies"
run: mix do local.rebar --force, local.hex --force, deps.get
- name: "Compile dependencies"
run: mix deps.compile
- name: "Compile Yggdrasil for PostgreSQL"
run: mix compile --warnings-as-errors
- name: "Check formatting"
run: mix format --dry-run --check-formatted
- name: "Run Credo"
run: mix credo --strict
- name: "Run tests"
run: mix test
env:
YGGDRASIL_POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }}
- name: "Run Dialyzer"
run: mix dialyzer
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ erl_crash.dump
.tool-versions

# PLTs
priv/plts/skogsra.plt
priv/plts/skogsra.plt.hash
priv/plts/yggdrasil_postgres.plt
priv/plts/yggdrasil_postgres.plt.hash

# Language server
.elixir_ls
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v6.0.0

* Updated dependencies.
* Updated docker-compose.
* Moved CI to Github.

## v5.0.2

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ available hex package to your `mix.exs` file e.g:

```elixir
def deps do
[{:yggdrasil_postgres, "~> 5.0"}]
[{:yggdrasil_postgres, "~> 6.0"}]
end
```

Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
postgres:
image: 'postgres:latest'
environment:
POSTGRES_DATABASE: travis_ci_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DATABASE: postgres
ports:
- '5432:5432'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Yggdrasil.Settings.Postgres do
defmodule Yggdrasil.Config.Postgres do
@moduledoc """
This module defines the available settings for PostgreSQL in Yggdrasil.
"""
Expand All @@ -14,32 +14,29 @@ defmodule Yggdrasil.Settings.Postgres do

@envdoc """
Postgres port. Defaults to `5432`.

iex> Yggdrasil.Settings.Postgres.port()
{:ok, 5432}
"""
app_env :port, :yggdrasil, [:postgres, :port], default: 5432

@envdoc """
Postgres username. Defaults to `"postgres"`.

iex> Yggdrasil.Settings.Postgres.username()
iex> Yggdrasil.Config.Postgres.username()
{:ok, "postgres"}
"""
app_env :username, :yggdrasil, [:postgres, :username], default: "postgres"

@envdoc """
Postgres password. Defaults to `"postgres"`.

iex> Yggdrasil.Settings.Postgres.password()
iex> Yggdrasil.Config.Postgres.password()
{:ok, "postgres"}
"""
app_env :password, :yggdrasil, [:postgres, :password], default: "postgres"

@envdoc """
Postgres database. Defaults to `"postgres"`.

iex> Yggdrasil.Settings.Postgres.database()
iex> Yggdrasil.Config.Postgres.database()
{:ok, "postgres"}
"""
app_env :database, :yggdrasil, [:postgres, :database], default: "postgres"
Expand All @@ -54,23 +51,23 @@ defmodule Yggdrasil.Settings.Postgres do
when `retries <= MAX_RETRIES` and `slot` is given by the configuration
variable `#{__MODULE__}.slot_size/0` (defaults to `10` secs).

iex> Yggdrasil.Settings.Postgres.max_retries()
iex> Yggdrasil.Config.Postgres.max_retries()
{:ok, 3}
"""
app_env :max_retries, :yggdrasil, [:postgres, :max_retries], default: 3

@envdoc """
Postgres slot size for the backoff algorithm. Defaults to `100`.

iex> Yggdrasil.Settings.Postgres.slot_size()
iex> Yggdrasil.Config.Postgres.slot_size()
{:ok, 10}
"""
app_env :slot_size, :yggdrasil, [:postgres, :slot_size], default: 10

@envdoc """
PostgreSQL amount of publisher connections.

iex> Yggdrasil.Settings.Postgres.publisher_connections()
iex> Yggdrasil.Config.Postgres.publisher_connections()
{:ok, 1}
"""
app_env :publisher_connections,
Expand All @@ -81,7 +78,7 @@ defmodule Yggdrasil.Settings.Postgres do
@envdoc """
PostgreSQL amount of subscriber connections.

iex> Yggdrasil.Settings.Postgres.subscriber_connections()
iex> Yggdrasil.Config.Postgres.subscriber_connections()
{:ok, 1}
"""
app_env :subscriber_connections,
Expand Down
16 changes: 8 additions & 8 deletions lib/yggdrasil/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Yggdrasil.Postgres.Connection do

require Logger

alias Yggdrasil.Settings.Postgres, as: Settings
alias Yggdrasil.Config.Postgres, as: Config

@typedoc """
Connection types.
Expand Down Expand Up @@ -192,11 +192,11 @@ defmodule Yggdrasil.Postgres.Connection do
@spec postgres_options(t()) :: Keyword.t()
def postgres_options(%State{namespace: namespace}) do
[
hostname: Settings.hostname!(namespace),
port: Settings.port!(namespace),
username: Settings.username!(namespace),
password: Settings.password!(namespace),
database: Settings.database!(namespace)
hostname: Config.hostname!(namespace),
port: Config.port!(namespace),
username: Config.username!(namespace),
password: Config.password!(namespace),
database: Config.database!(namespace)
]
end

Expand All @@ -205,8 +205,8 @@ defmodule Yggdrasil.Postgres.Connection do
def backoff(error, state)

def backoff(error, %State{namespace: namespace, retries: retries} = state) do
max_retries = Settings.max_retries!(namespace)
slot_size = Settings.slot_size!(namespace)
max_retries = Config.max_retries!(namespace)
slot_size = Config.slot_size!(namespace)

new_backoff = (2 <<< retries) * Enum.random(1..slot_size) * 1000
Process.send_after(self(), {:timeout, {:continue, :connect}}, new_backoff)
Expand Down
4 changes: 3 additions & 1 deletion lib/yggdrasil/postgres/connection/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ defmodule Yggdrasil.Postgres.Connection.Generator do
Starts a connection pool generator.
"""
@spec start_link() :: Supervisor.on_start()
@spec start_link([DynamicSupervisor.option() | DynamicSupervisor.init_option()]) ::
@spec start_link([
DynamicSupervisor.option() | DynamicSupervisor.init_option()
]) ::
Supervisor.on_start()
def start_link(options \\ []) do
DynamicSupervisor.start_link(__MODULE__, nil, options)
Expand Down
6 changes: 3 additions & 3 deletions lib/yggdrasil/postgres/connection/pool.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule Yggdrasil.Postgres.Connection.Pool do
"""
use Supervisor

alias Yggdrasil.Config.Postgres, as: Config
alias Yggdrasil.Postgres.Connection
alias Yggdrasil.Settings.Postgres, as: Settings

############
# Public API
Expand Down Expand Up @@ -88,12 +88,12 @@ defmodule Yggdrasil.Postgres.Connection.Pool do
defp get_pool_size(tag, namespace)

defp get_pool_size(:subscriber, namespace) do
{:ok, size} = Settings.subscriber_connections(namespace)
{:ok, size} = Config.subscriber_connections(namespace)
size
end

defp get_pool_size(:publisher, namespace) do
{:ok, size} = Settings.publisher_connections(namespace)
{:ok, size} = Config.publisher_connections(namespace)
size
end
end
31 changes: 20 additions & 11 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
defmodule YggdrasilPostgres.MixProject do
use Mix.Project

@version "5.0.2"
@version "6.0.0"
@root "https://github.com/gmtprime/yggdrasil_postgres"

def project do
[
name: "Yggdrasil for PostgreSQL",
app: :yggdrasil_postgres,
version: @version,
elixir: "~> 1.8",
elixir: "~> 1.12",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
dialyzer: dialyzer(),
package: package(),
deps: deps(),
docs: docs()
Expand All @@ -30,12 +31,18 @@ defmodule YggdrasilPostgres.MixProject do

defp deps do
[
{:yggdrasil, "~> 5.0"},
{:skogsra, "~> 2.2"},
{:yggdrasil, "~> 6.0"},
{:skogsra, "~> 2.3"},
{:postgrex, "~> 0.15"},
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
{:credo, "~> 1.2", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0-rc.7", only: :dev, runtime: false}
{:ex_doc, "~> 0.24", only: [:dev, :test], runtime: false},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}
]
end

def dialyzer do
[
plt_file: {:no_warn, "priv/plts/yggdrasil_postgres.plt"}
]
end

Expand All @@ -60,12 +67,14 @@ defmodule YggdrasilPostgres.MixProject do

defp docs do
[
main: "readme",
source_url: @root,
source_ref: "v#{@version}",
main: "readme",
formatters: ["html"],
groups_for_modules: groups_for_modules(),
extras: ["README.md"]
extras: [
"README.md",
"CHANGELOG.md"
],
groups_for_modules: groups_for_modules()
]
end

Expand Down
Loading