PageRenderTime 19ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/backends/search/solr/uce_solr_commiter.erl

http://github.com/AF83/ucengine
Erlang | 60 lines | 31 code | 12 blank | 17 comment | 0 complexity | 967b6f2192b2925ef6d810314cf3bf0c MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(uce_solr_commiter).
  19. -behaviour(gen_server).
  20. -include("uce.hrl").
  21. -export([start_link/0]).
  22. -export([init/1,
  23. code_change/3,
  24. handle_call/3,
  25. handle_cast/2,
  26. handle_info/2,
  27. terminate/2]).
  28. start_link() ->
  29. gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
  30. init([]) ->
  31. gen_server:cast(?MODULE, run),
  32. {ok, nothing}.
  33. handle_call(_ , _, State) ->
  34. {reply, ok, State}.
  35. handle_cast(run, State) ->
  36. [CommitInterval] = utils:get(config:get(solr), [commit_interval], [1000]),
  37. timer:sleep(CommitInterval),
  38. {ok, commited} = uce_event_solr_search:commit(),
  39. handle_cast(run, State),
  40. {noreply, State};
  41. handle_cast(_, State) ->
  42. {noreply, State}.
  43. code_change(_,State,_) ->
  44. {ok, State}.
  45. handle_info(_Info, State) ->
  46. {reply, State}.
  47. terminate(_Reason, _State) ->
  48. ok.