Packages
Quantum Storage Adapter based on Persistent ETS
Current section
2 Versions
Jump to
Current section
2 Versions
Compare versions
5
files changed
+67
additions
-86
deletions
| @@ -4,7 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/). | |
| 4 4 | |
| 5 5 | ## Unreleased |
| 6 6 | |
| 7 | - Diff for [unreleased](https://github.com/quantum-elixir/quantum-storage-persistent-ets/compare/v1.0.0-rc.1...HEAD) |
| 7 | + Diff for [unreleased](https://github.com/quantum-elixir/quantum-storage-persistent-ets/compare/v1.0.0...HEAD) |
| 8 | + |
| 9 | + ## v1.0.0 |
| 10 | + |
| 11 | + Diff for [v1.0.0](https://github.com/quantum-elixir/quantum-storage-persistent-ets/compare/v1.0.0-rc.1...v1.0.0) |
| 8 12 | |
| 9 13 | ## v1.0.0-rc.1 |
| @@ -16,7 +16,7 @@ of dependencies in `mix.exs`: | |
| 16 16 | ```elixir |
| 17 17 | def deps do |
| 18 18 | [ |
| 19 | - {:quantum_storage_persistent_ets, "~> 1.0-rc"} |
| 19 | + {:quantum_storage_persistent_ets, "~> 1.0"} |
| 20 20 | ] |
| 21 21 | end |
| 22 22 | ``` |
| @@ -19,10 +19,10 @@ | |
| 19 19 | {<<"name">>,<<"persistent_ets">>}, |
| 20 20 | {<<"optional">>,false}, |
| 21 21 | {<<"repository">>,<<"hexpm">>}, |
| 22 | - {<<"requirement">>,<<"~> 0.1">>}], |
| 22 | + {<<"requirement">>,<<"~> 0.2">>}], |
| 23 23 | [{<<"app">>,<<"quantum">>}, |
| 24 24 | {<<"name">>,<<"quantum">>}, |
| 25 25 | {<<"optional">>,false}, |
| 26 26 | {<<"repository">>,<<"hexpm">>}, |
| 27 | - {<<"requirement">>,<<"~> 3.0.0-rc.2">>}]]}. |
| 28 | - {<<"version">>,<<"1.0.0-rc.1">>}. |
| 27 | + {<<"requirement">>,<<"~> 3.0">>}]]}. |
| 28 | + {<<"version">>,<<"1.0.0">>}. |
| @@ -47,16 +47,16 @@ defmodule QuantumStoragePersistentEts do | |
| 47 47 | |
| 48 48 | @doc false |
| 49 49 | @impl Quantum.Storage |
| 50 | - def add_job(storage_pid, job), do: GenServer.call(storage_pid, {:add_job, job}) |
| 50 | + def add_job(storage_pid, job), do: GenServer.cast(storage_pid, {:add_job, job}) |
| 51 51 | |
| 52 52 | @doc false |
| 53 53 | @impl Quantum.Storage |
| 54 | - def delete_job(storage_pid, job_name), do: GenServer.call(storage_pid, {:delete_job, job_name}) |
| 54 | + def delete_job(storage_pid, job_name), do: GenServer.cast(storage_pid, {:delete_job, job_name}) |
| 55 55 | |
| 56 56 | @doc false |
| 57 57 | @impl Quantum.Storage |
| 58 58 | def update_job_state(storage_pid, job_name, state), |
| 59 | - do: GenServer.call(storage_pid, {:update_job_state, job_name, state}) |
| 59 | + do: GenServer.cast(storage_pid, {:update_job_state, job_name, state}) |
| 60 60 | |
| 61 61 | @doc false |
| 62 62 | @impl Quantum.Storage |
| @@ -65,51 +65,15 @@ defmodule QuantumStoragePersistentEts do | |
| 65 65 | @doc false |
| 66 66 | @impl Quantum.Storage |
| 67 67 | def update_last_execution_date(storage_pid, last_execution_date), |
| 68 | - do: GenServer.call(storage_pid, {:update_last_execution_date, last_execution_date}) |
| 68 | + do: GenServer.cast(storage_pid, {:update_last_execution_date, last_execution_date}) |
| 69 69 | |
| 70 70 | @doc false |
| 71 71 | @impl Quantum.Storage |
| 72 | - def purge(storage_pid), do: GenServer.call(storage_pid, :purge) |
| 72 | + def purge(storage_pid), do: GenServer.cast(storage_pid, :purge) |
| 73 73 | |
| 74 74 | @doc false |
| 75 75 | @impl GenServer |
| 76 | - def handle_call({:add_job, job}, _from, %State{table: table} = state) do |
| 77 | - {:reply, do_add_job(table, job), state} |
| 78 | - end |
| 79 | - |
| 80 | - def handle_call(:jobs, _from, %State{table: table} = state) do |
| 81 | - {:reply, do_get_jobs(table), state} |
| 82 | - end |
| 83 | - |
| 84 | - def handle_call({:delete_job, job}, _from, %State{table: table} = state) do |
| 85 | - {:reply, do_delete_job(table, job), state} |
| 86 | - end |
| 87 | - |
| 88 | - def handle_call({:update_job_state, job_name, job_state}, _from, %State{table: table} = state) do |
| 89 | - {:reply, do_update_job_state(table, job_name, job_state), state} |
| 90 | - end |
| 91 | - |
| 92 | - def handle_call(:last_execution_date, _from, %State{table: table} = state) do |
| 93 | - {:reply, do_get_last_execution_date(table), state} |
| 94 | - end |
| 95 | - |
| 96 | - def handle_call( |
| 97 | - {:update_last_execution_date, last_execution_date}, |
| 98 | - _from, |
| 99 | - %State{table: table} = state |
| 100 | - ) do |
| 101 | - {:reply, do_update_last_execution_date(table, last_execution_date), state} |
| 102 | - end |
| 103 | - |
| 104 | - def handle_call(:purge, _from, %State{table: table} = state) do |
| 105 | - {:reply, do_purge(table), state} |
| 106 | - end |
| 107 | - |
| 108 | - defp job_key(job_name) do |
| 109 | - {:job, job_name} |
| 110 | - end |
| 111 | - |
| 112 | - defp do_add_job(table, job) do |
| 76 | + def handle_cast({:add_job, job}, %State{table: table} = state) do |
| 113 77 | :ets.insert(table, entry = {job_key(job.name), job}) |
| 114 78 | :ets.insert(table, {:init_jobs}) |
| 115 79 | |
| @@ -119,54 +83,67 @@ defmodule QuantumStoragePersistentEts do | |
| 119 83 | }]" |
| 120 84 | end) |
| 121 85 | |
| 122 | - :ok |
| 86 | + {:noreply, state} |
| 123 87 | end |
| 124 88 | |
| 125 | - defp do_get_jobs(table) do |
| 126 | - table |
| 127 | - |> :ets.lookup(:init_jobs) |
| 128 | - |> case do |
| 129 | - [{:init_jobs}] -> |
| 130 | - table |
| 131 | - |> :ets.match({{:job, :_}, :"$1"}) |
| 132 | - |> List.flatten() |
| 133 | - |
| 134 | - [] -> |
| 135 | - :not_applicable |
| 136 | - end |
| 137 | - end |
| 138 | - |
| 139 | - defp do_delete_job(table, job_name) do |
| 89 | + def handle_cast({:delete_job, job_name}, %State{table: table} = state) do |
| 140 90 | :ets.delete(table, job_key(job_name)) |
| 141 91 | |
| 142 | - :ok |
| 92 | + {:noreply, state} |
| 143 93 | end |
| 144 94 | |
| 145 | - defp do_update_job_state(table, job_name, state) do |
| 95 | + def handle_cast({:update_job_state, job_name, job_state}, %State{table: table} = state) do |
| 146 96 | table |
| 147 97 | |> :ets.lookup(job_key(job_name)) |
| 148 | - |> Enum.map(&{elem(&1, 0), %{elem(&1, 1) | state: state}}) |
| 98 | + |> Enum.map(&{elem(&1, 0), %{elem(&1, 1) | state: job_state}}) |
| 149 99 | |> Enum.each(&:ets.update_element(table, elem(&1, 0), {2, elem(&1, 1)})) |
| 150 100 | |
| 151 | - :ok |
| 101 | + {:noreply, state} |
| 152 102 | end |
| 153 103 | |
| 154 | - defp do_get_last_execution_date(table) do |
| 155 | - table |
| 156 | - |> :ets.lookup(:last_execution_date) |
| 157 | - |> case do |
| 158 | - [] -> :unknown |
| 159 | - [{:last_execution_date, date} | _t] -> date |
| 160 | - end |
| 161 | - end |
| 162 | - |
| 163 | - defp do_update_last_execution_date(table, last_execution_date) do |
| 104 | + def handle_cast( |
| 105 | + {:update_last_execution_date, last_execution_date}, |
| 106 | + %State{table: table} = state |
| 107 | + ) do |
| 164 108 | :ets.insert(table, {:last_execution_date, last_execution_date}) |
| 165 | - :ok |
| 109 | + |
| 110 | + {:noreply, state} |
| 166 111 | end |
| 167 112 | |
| 168 | - defp do_purge(table) do |
| 113 | + def handle_cast(:purge, %State{table: table} = state) do |
| 169 114 | :ets.delete_all_objects(table) |
| 170 | - :ok |
| 115 | + |
| 116 | + {:noreply, state} |
| 117 | + end |
| 118 | + |
| 119 | + @doc false |
| 120 | + @impl GenServer |
| 121 | + def handle_call(:jobs, _from, %State{table: table} = state) do |
| 122 | + {:reply, |
| 123 | + table |
| 124 | + |> :ets.lookup(:init_jobs) |
| 125 | + |> case do |
| 126 | + [{:init_jobs}] -> |
| 127 | + table |
| 128 | + |> :ets.match({{:job, :_}, :"$1"}) |
| 129 | + |> List.flatten() |
| 130 | + |
| 131 | + [] -> |
| 132 | + :not_applicable |
| 133 | + end, state} |
| 134 | + end |
| 135 | + |
| 136 | + def handle_call(:last_execution_date, _from, %State{table: table} = state) do |
| 137 | + {:reply, |
| 138 | + table |
| 139 | + |> :ets.lookup(:last_execution_date) |
| 140 | + |> case do |
| 141 | + [] -> :unknown |
| 142 | + [{:last_execution_date, date} | _t] -> date |
| 143 | + end, state} |
| 144 | + end |
| 145 | + |
| 146 | + defp job_key(job_name) do |
| 147 | + {:job, job_name} |
| 171 148 | end |
| 172 149 | end |
| @@ -3,7 +3,7 @@ defmodule QuantumStoragePersistentEts.MixProject do | |
| 3 3 | |
| 4 4 | use Mix.Project |
| 5 5 | |
| 6 | - @version "1.0.0-rc.1" |
| 6 | + @version "1.0.0" |
| 7 7 | |
| 8 8 | def project do |
| 9 9 | [ |
| @@ -74,12 +74,12 @@ defmodule QuantumStoragePersistentEts.MixProject do | |
| 74 74 | # Run "mix help deps" to learn about dependencies. |
| 75 75 | defp deps do |
| 76 76 | [ |
| 77 | - {:persistent_ets, "~> 0.1"}, |
| 78 | - {:quantum, "~> 3.0.0-rc.2"}, |
| 77 | + {:persistent_ets, "~> 0.2"}, |
| 78 | + {:quantum, "~> 3.0"}, |
| 79 79 | {:ex_doc, "~> 0.13", only: [:dev, :docs], runtime: false}, |
| 80 | - {:excoveralls, "~> 0.5", only: [:dev, :test], runtime: false}, |
| 81 | - {:dialyxir, "~> 1.0-rc", only: [:dev, :test], runtime: false}, |
| 82 | - {:credo, "~> 1.0", only: [:dev, :test], runtime: false} |
| 80 | + {:excoveralls, "~> 0.13", only: [:dev, :test], runtime: false}, |
| 81 | + {:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}, |
| 82 | + {:credo, "~> 1.4", only: [:dev, :test], runtime: false} |
| 83 83 | ] |
| 84 84 | end |
| 85 85 | end |