Current section
6 Versions
Jump to
Current section
6 Versions
Compare versions
7
files changed
+68
additions
-17
deletions
| @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
| 6 6 | |
| 7 7 | ## [Unreleased] |
| 8 8 | |
| 9 | + ## [0.7.0] - 2019-09-06 |
| 10 | + ### Changed |
| 11 | + - Updated for Dawdle v0.7.0. |
| 12 | + |
| 9 13 | ## [0.6.0] - 2019-08-05 |
| 10 14 | ### Added |
| 11 15 | - Telemetry events are now fired during event handling. |
| @@ -10,7 +10,7 @@ dependencies in `mix.exs`: | |
| 10 10 | ```elixir |
| 11 11 | def deps do |
| 12 12 | [ |
| 13 | - {:dawdle_db, "~> 0.5.0"} |
| 13 | + {:dawdle_db, "~> 0.7.0"} |
| 14 14 | ] |
| 15 15 | end |
| 16 16 | ``` |
| @@ -9,8 +9,8 @@ | |
| 9 9 | <<"lib/dawdle_db/watcher/swarm_container.ex">>, |
| 10 10 | <<"lib/dawdle_db/watcher/watcher.ex">>,<<"lib/dawdle_db/event.ex">>, |
| 11 11 | <<"lib/dawdle_db/test_helper.ex">>,<<"lib/dawdle_db/handler.ex">>, |
| 12 | - <<"lib/dawdle_db/migration.ex">>,<<"priv">>,<<"priv/repo">>, |
| 13 | - <<"priv/repo/migrations">>, |
| 12 | + <<"lib/dawdle_db/migration.ex">>,<<"lib/dawdle_db/cleaner.ex">>,<<"priv">>, |
| 13 | + <<"priv/repo">>,<<"priv/repo/migrations">>, |
| 14 14 | <<"priv/repo/migrations/20190313211937_test_db.exs">>,<<".formatter.exs">>, |
| 15 15 | <<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,<<"CHANGELOG.md">>]}. |
| 16 16 | {<<"licenses">>,[<<"MIT">>]}. |
| @@ -26,7 +26,7 @@ | |
| 26 26 | {<<"name">>,<<"dawdle">>}, |
| 27 27 | {<<"optional">>,false}, |
| 28 28 | {<<"repository">>,<<"hexpm">>}, |
| 29 | - {<<"requirement">>,<<"~> 0.6">>}], |
| 29 | + {<<"requirement">>,<<"~> 0.7">>}], |
| 30 30 | [{<<"app">>,<<"ecto">>}, |
| 31 31 | {<<"name">>,<<"ecto">>}, |
| 32 32 | {<<"optional">>,false}, |
| @@ -42,11 +42,6 @@ | |
| 42 42 | {<<"optional">>,false}, |
| 43 43 | {<<"repository">>,<<"hexpm">>}, |
| 44 44 | {<<"requirement">>,<<"~> 2.0">>}], |
| 45 | - [{<<"app">>,<<"ex_aws_sqs">>}, |
| 46 | - {<<"name">>,<<"ex_aws_sqs">>}, |
| 47 | - {<<"optional">>,false}, |
| 48 | - {<<"repository">>,<<"hexpm">>}, |
| 49 | - {<<"requirement">>,<<"~> 2.0">>}], |
| 50 45 | [{<<"app">>,<<"poison">>}, |
| 51 46 | {<<"name">>,<<"poison">>}, |
| 52 47 | {<<"optional">>,false}, |
| @@ -72,4 +67,4 @@ | |
| 72 67 | {<<"optional">>,false}, |
| 73 68 | {<<"repository">>,<<"hexpm">>}, |
| 74 69 | {<<"requirement">>,<<"~> 3.5">>}]]}. |
| 75 | - {<<"version">>,<<"0.6.0">>}. |
| 70 | + {<<"version">>,<<"0.7.0">>}. |
| @@ -0,0 +1,51 @@ | |
| 1 | + defmodule DawdleDB.Cleaner do |
| 2 | + @moduledoc """ |
| 3 | + Regularly cleans out the events table and logs any stale entries that |
| 4 | + were not processed. |
| 5 | + """ |
| 6 | + |
| 7 | + use GenServer |
| 8 | + |
| 9 | + @clean_interval :timer.hours(1) |
| 10 | + @clean_older_than [hours: -1] |
| 11 | + |
| 12 | + require Logger |
| 13 | + |
| 14 | + @doc false |
| 15 | + @spec start_link(any()) :: GenServer.on_start() |
| 16 | + def start_link(init_arg) do |
| 17 | + GenServer.start_link(__MODULE__, init_arg, name: __MODULE__) |
| 18 | + end |
| 19 | + |
| 20 | + @impl true |
| 21 | + def init(_) do |
| 22 | + {:ok, nil, 0} |
| 23 | + end |
| 24 | + |
| 25 | + @impl true |
| 26 | + def handle_info(:timeout, state) do |
| 27 | + timestamp = Timex.shift(DateTime.utc_now(), @clean_older_than) |
| 28 | + |
| 29 | + result = |
| 30 | + Postgrex.query!( |
| 31 | + :watcher_postgrex, |
| 32 | + "DELETE FROM watcher_events WHERE created_at < $1 RETURNING *", |
| 33 | + [timestamp] |
| 34 | + ) |
| 35 | + |
| 36 | + _ = |
| 37 | + case result.num_rows do |
| 38 | + 0 -> |
| 39 | + :ok |
| 40 | + |
| 41 | + _ -> |
| 42 | + Logger.error( |
| 43 | + "Cleaned #{result.num_rows} from watcher events table: #{inspect(result.rows)}" |
| 44 | + ) |
| 45 | + end |
| 46 | + |
| 47 | + {:noreply, state, @clean_interval} |
| 48 | + end |
| 49 | + |
| 50 | + def handle_info(_info, state), do: {:noreply, state} |
| 51 | + end |
| @@ -25,7 +25,8 @@ defmodule DawdleDB.Watcher.Supervisor do | |
| 25 25 | {Postgrex.Notifications, :start_link, |
| 26 26 | [Keyword.put(config, :name, :watcher_notifications)]} |
| 27 27 | }, |
| 28 | - {DawdleDB.Watcher, []} |
| 28 | + {DawdleDB.Watcher, []}, |
| 29 | + {DawdleDB.Cleaner, []} |
| 29 30 | ] |
| 30 31 | |
| 31 32 | Supervisor.init(children, strategy: :rest_for_one) |
Loading more files…