Skip to content

Commit

Permalink
create table on start if it’s not already created
Browse files Browse the repository at this point in the history
  • Loading branch information
4xposed committed Feb 2, 2020
1 parent 6009572 commit 4f6c77c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/minirate/counter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ defmodule Minirate.Counter do

def create_mnesia_table(table) do
Mnesia.create_table(table, attributes: [:key, :count, :timestamp])
Mnesia.add_table_index(table, :timestamp)
end
end
7 changes: 2 additions & 5 deletions lib/minirate/worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ defmodule Minirate.Worker do
GenServer.call(__MODULE__, {:check_limit, action, id, limit})
end

def create_table do
GenServer.info(__MODULE__, :create_table)
end

# GenServer Callbacks

def init(args) do
Process.send_after(self(), :create_table, 500)
:timer.send_interval(args.cleanup_period_ms, :expire)

{:ok, args}
Expand All @@ -48,7 +45,7 @@ defmodule Minirate.Worker do

def handle_info(:create_table, state) do
Counter.create_mnesia_table(state.mnesia_table)
Worker.create_table()
{:noreply, state}
end

defp now do
Expand Down

0 comments on commit 4f6c77c

Please sign in to comment.