Skip to content

Commit

Permalink
Able to set timeout with object-length
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Dec 10, 2012
1 parent f4acac1 commit 1c9824a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
34 changes: 32 additions & 2 deletions include/leo_gateway.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
-define(TIMEOUT_L1_SEC, 5000).
-define(TIMEOUT_L2_SEC, 7000).
-define(TIMEOUT_L3_SEC, 10000).
-define(TIMEOUT_L4_SEC, 12000).
-define(TIMEOUT_L5_SEC, 15000).
-define(TIMEOUT_L4_SEC, 20000).
-define(TIMEOUT_L5_SEC, 30000).


%% macros.
Expand All @@ -92,6 +92,36 @@
_ -> ?S3_HTTP
end).

-define(env_timeout_level_1(),
case application:get_env(leo_gateway, timeout_level_1) of
{ok, EnvTimeoutL1} -> EnvTimeoutL1;
_ -> ?TIMEOUT_L1_SEC
end).

-define(env_timeout_level_2(),
case application:get_env(leo_gateway, timeout_level_2) of
{ok, EnvTimeoutL2} -> EnvTimeoutL2;
_ -> ?TIMEOUT_L2_SEC
end).

-define(env_timeout_level_3(),
case application:get_env(leo_gateway, timeout_level_3) of
{ok, EnvTimeoutL3} -> EnvTimeoutL3;
_ -> ?TIMEOUT_L3_SEC
end).

-define(env_timeout_level_4(),
case application:get_env(leo_gateway, timeout_level_4) of
{ok, EnvTimeoutL4} -> EnvTimeoutL4;
_ -> ?TIMEOUT_L4_SEC
end).

-define(env_timeout_level_5(),
case application:get_env(leo_gateway, timeout_level_5) of
{ok, EnvTimeoutL5} -> EnvTimeoutL5;
_ -> ?TIMEOUT_L5_SEC
end).


%% REQ/RESP ERRORS
-record(error_code, {
Expand Down
10 changes: 5 additions & 5 deletions src/leo_gateway_rpc_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ handle_error(Node, Mod, Method, _Args, timeout = Error) ->

%% @doc Timeout depends on length of an object
%%
timeout(Len) when ?TIMEOUT_L1_LEN > Len -> ?TIMEOUT_L1_SEC;
timeout(Len) when ?TIMEOUT_L2_LEN > Len -> ?TIMEOUT_L2_SEC;
timeout(Len) when ?TIMEOUT_L3_LEN > Len -> ?TIMEOUT_L3_SEC;
timeout(Len) when ?TIMEOUT_L4_LEN > Len -> ?TIMEOUT_L4_SEC;
timeout(_) -> ?TIMEOUT_L5_SEC.
timeout(Len) when ?TIMEOUT_L1_LEN > Len -> ?env_timeout_level_1();
timeout(Len) when ?TIMEOUT_L2_LEN > Len -> ?env_timeout_level_2();
timeout(Len) when ?TIMEOUT_L3_LEN > Len -> ?env_timeout_level_3();
timeout(Len) when ?TIMEOUT_L4_LEN > Len -> ?env_timeout_level_4();
timeout(_) -> ?env_timeout_level_5().

timeout(put, [#object{dsize = DSize}, _]) ->
timeout(DSize);
Expand Down

0 comments on commit 1c9824a

Please sign in to comment.