-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inaki.worker pool #31
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b43c1ae
Added worker pool.
igaray 94b7238
Merge branch 'marcelog_dynamic_dependencies_6' into inaki.worker_pool
igaray 261a82e
added storage backend concept
igaray ab750f9
Removed debug lagers.
igaray 44c8d0c
Merge branch 'master' into inaki.worker_pool
igaray 0cc9cf8
PR corrections
igaray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ | |
warn_untyped_record, debug_info | ||
]}. | ||
{deps, [ | ||
{'lager', ".*", { | ||
git, "git://github.com/basho/lager.git", "2.0.0"} | ||
} | ||
{'lager', ".*", {git, "git://github.com/basho/lager.git", "2.0.0"}}, | ||
{emysql, "0.*", {git, "[email protected]:Eonblast/Emysql.git", "master"}}, | ||
{emongo, ".*", {git, "[email protected]:JacobVorreuter/emongo.git", "HEAD"}}, | ||
{eredis, ".*", {git, "[email protected]:wooga/eredis.git", "HEAD"}}, | ||
{'sqlite3', ".*", {git, "[email protected]:alexeyr/erlang-sqlite3.git", "HEAD"}}, | ||
{worker_pool, ".*", {git, "[email protected]:inaka/worker_pool.git", "master"}} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
%%% @doc Main interface for repositories. | ||
%%% | ||
%%% Copyright 2012 Marcelo Gornstein <marcelog@@gmail.com> | ||
%%% | ||
%%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%%% you may not use this file except in compliance with the License. | ||
%%% You may obtain a copy of the License at | ||
%%% | ||
%%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%%% | ||
%%% Unless required by applicable law or agreed to in writing, software | ||
%%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%%% See the License for the specific language governing permissions and | ||
%%% limitations under the License. | ||
%%% @end | ||
%%% @copyright Marcelo Gornstein <[email protected]> | ||
%%% @author Marcelo Gornstein <[email protected]> | ||
%%% | ||
-module(sumo_backend_mysql). | ||
-author("Marcelo Gornstein <[email protected]>"). | ||
-github("https://github.com/marcelog"). | ||
-homepage("http://marcelog.github.com/"). | ||
-license("Apache License 2.0"). | ||
|
||
-behaviour(gen_server). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Exports. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%%% Public API. | ||
|
||
%%% Exports for gen_server | ||
-export( | ||
[ init/1 | ||
, handle_call/3 | ||
, handle_cast/2 | ||
, handle_info/2 | ||
, terminate/2 | ||
, code_change/3 | ||
]). | ||
-export( | ||
[ get_pool/1 | ||
]). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Types. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
-record(state, { | ||
pool = undefined :: atom() | ||
}). | ||
-type state() :: #state{}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% External API. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec get_pool(atom() | pid()) -> atom(). | ||
get_pool(Name) -> | ||
gen_server:call(Name, get_pool). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% gen_server stuff. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec init([term()]) -> {ok, #state{}}. | ||
init(Options) -> | ||
PoolSize = proplists:get_value(poolsize, Options), | ||
Pool = list_to_atom(erlang:ref_to_list(make_ref())), | ||
emysql:add_pool( | ||
Pool, | ||
PoolSize, | ||
proplists:get_value(username, Options), | ||
proplists:get_value(password, Options), | ||
proplists:get_value(host, Options, "localhost"), | ||
proplists:get_value(port, Options, 3306), | ||
proplists:get_value(database, Options), | ||
proplists:get_value(encoding, Options, utf8) | ||
), | ||
{ok, #state{pool=Pool}}. | ||
|
||
-spec handle_call(term(), term(), state()) -> {reply, term(), #state{}}. | ||
handle_call(get_pool, _From, State = #state{pool=Pool}) -> | ||
{reply, Pool, State}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%% Unused Callbacks | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
-spec handle_cast(term(), #state{}) -> {noreply, #state{}}. | ||
handle_cast(_Msg, State) -> {noreply, State}. | ||
|
||
-spec handle_info(term(), #state{}) -> {noreply, #state{}}. | ||
handle_info(_Msg, State) -> {noreply, State}. | ||
|
||
-spec terminate(term(), #state{}) -> ok. | ||
terminate(_Reason, _State) -> ok. | ||
|
||
-spec code_change(term(), #state{}, term()) -> {ok, #state{}}. | ||
code_change(_OldVsn, State, _Extra) -> {ok, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
%%% @doc Repository supervisor. | ||
%%% | ||
%%% Copyright 2012 Marcelo Gornstein <marcelog@@gmail.com> | ||
%%% | ||
%%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%%% you may not use this file except in compliance with the License. | ||
%%% You may obtain a copy of the License at | ||
%%% | ||
%%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%%% | ||
%%% Unless required by applicable law or agreed to in writing, software | ||
%%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%%% See the License for the specific language governing permissions and | ||
%%% limitations under the License. | ||
%%% @end | ||
%%% @copyright Marcelo Gornstein <[email protected]> | ||
%%% @author Marcelo Gornstein <[email protected]> | ||
%%% | ||
-module(sumo_backend_sup). | ||
-author("Marcelo Gornstein <[email protected]>"). | ||
-github("https://github.com/marcelog"). | ||
-homepage("http://marcelog.github.com/"). | ||
-license("Apache License 2.0"). | ||
|
||
-define(CLD(Name, Module, Options), { | ||
Module, | ||
{gen_server, start_link, [{local, Name}, Module, Options, []]}, | ||
permanent, 5000, worker, [Module] | ||
}). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Exports. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
-export([start_link/0]). | ||
-export([init/1]). | ||
|
||
-behaviour(supervisor). | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%% Code starts here. | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
init([]) -> | ||
{ok, Backends} = application:get_env(sumo_db, storage_backends), | ||
Children = lists:map( | ||
fun({Name, Module, Options}) -> | ||
lager:debug("starting backend: ~s (~s)", [Name, Module]), | ||
?CLD(Name, Module, Options) | ||
end, | ||
Backends | ||
), | ||
{ok, { {one_for_one, 5, 10}, Children} }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,8 @@ | |
stdlib, | ||
sasl, | ||
lager, | ||
crypto | ||
crypto, | ||
worker_pool | ||
]}, | ||
{mod, { sumo_app, []}}, | ||
{env, []} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved start_link and create_schema from below so that it matches the export order.