Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add ets_opts arg

  • Loading branch information...
commit 5d37d45c1f2ed325beaa1177ba54045e902d7529 1 parent e3205ad
@jkvor jkvor authored
Showing with 8 additions and 3 deletions.
  1. +2 −1  README.md
  2. +6 −2 src/lockstep.erl
View
3  README.md
@@ -27,12 +27,13 @@ All records sent must have a deleted_at attribute which should be null normally,
start_link(Uri, Opts) -> Result
Uri = list() %% http endpoint to pull data from
Opts = [Opt]
- Opt = {callback, Callback} | {table, TabName} | {disk, SyncToDisk} | {order_by, OrderField}
+ Opt = {callback, Callback} | {table, TabName} | {ets_opts, EtsOpts} | {disk, SyncToDisk} | {order_by, OrderField}
Callback = {Module, Function, Args}
Module = atom()
Function = atom()
Args = list()
TabName = atom() %% the name of the ets (and optionally dets) table to which lockstep data is written
+ EtsOpts = list() %% arguments to pass to ets:new
SyncToDisk = boolean() %% if the options list contains {disk, true}, lockstep will
%% sync its ets table to disk and pick up the stream from where
%% the dets table left off rather that resyncing the whole data set.
View
8 src/lockstep.erl
@@ -38,6 +38,7 @@
fsm,
tid=?MODULE,
disk=false,
+ ets_opts=[],
order_by = <<"updated_at">>,
uri,
callback,
@@ -131,6 +132,8 @@ init_state([{table, TabName}|Tail], State) when is_atom(TabName) ->
init_state(Tail, State#state{tid=TabName});
init_state([{disk, Disk}|Tail], State) when is_boolean(Disk) ->
init_state(Tail, State#state{disk=Disk});
+init_state([{ets_opts, Opts}|Tail], State) when is_list(Opts) ->
+ init_state(Tail, State#state{ets_opts=Opts});
init_state([{order_by, OrderBy}|Tail], State) when is_atom(OrderBy) ->
init_state(Tail, State#state{order_by=list_to_binary(atom_to_list(OrderBy))});
init_state([{uri, Uri}|Tail], State) ->
@@ -198,8 +201,9 @@ delete_dets(Time, Record, Tid) ->
dets:delete_object(Tid, Record),
dets:insert(Tid, {lockstep_head, Time}).
-setup_tables(#state{tid=TabName, disk=Disk}) when is_atom(TabName) ->
- TabName = ets:new(TabName, [named_table, set, protected, {read_concurrency, true}]),
+setup_tables(#state{tid=TabName, disk=Disk, ets_opts=Opts}) when is_atom(TabName) ->
+ Opts1 = [named_table, set, protected, {read_concurrency, true} | Opts],
+ TabName = ets:new(TabName, Opts1),
Disk == true andalso setup_dets(TabName).
setup_dets(TabName) ->
Please sign in to comment.
Something went wrong with that request. Please try again.