summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Feuer <mfeuer@jaguarlandrover.com>2015-06-08 14:59:21 -0700
committerMagnus Feuer <mfeuer@jaguarlandrover.com>2015-06-09 13:54:45 -0700
commit72d2d4ab6c126c166d0d17d710bf2c25802d471f (patch)
treee678c58766b711bfaaa94bfddcdd2997c86b661a
parent2f3850291b8c34613cecd266b88d908ff677b145 (diff)
downloadrvi_core-72d2d4ab6c126c166d0d17d710bf2c25802d471f.tar.gz
Converted timeout management to Unix time in msec
-rw-r--r--components/schedule/src/schedule_rpc.erl52
-rw-r--r--components/service_edge/src/service_edge_rpc.erl26
2 files changed, 39 insertions, 39 deletions
diff --git a/components/schedule/src/schedule_rpc.erl b/components/schedule/src/schedule_rpc.erl
index 89ca7a8..17bcf83 100644
--- a/components/schedule/src/schedule_rpc.erl
+++ b/components/schedule/src/schedule_rpc.erl
@@ -437,7 +437,7 @@ queue_message(SvcName,
Certificate,
St) ->
- TOut = calc_relative_tout(Timeout),
+ TOut = calc_relative_tout(Timeout),
?debug("sched:q(~s): No more routes. Will orphan for ~p seconds.",
[ SvcName, TOut / 1000.0]),
%% Stash in Service / orphaned
@@ -825,47 +825,25 @@ create_transaction_id(St) ->
%% schedulers?
{ ID, St#st { next_transaction_id = ID + 1 }}.
-%% Calculate a relative timeout based on the UnixTime TS we are provided with.
-calc_relative_tout(UnixTime) ->
- { Mega, Sec, _Micro } = now(),
- Now = Mega * 1000000 + Sec,
+%% Calculate a relative timeout based on the Msec UnixTime TS we are
+%% provided with.
+calc_relative_tout(UnixTimeMS) ->
+ { Mega, Sec, Micro } = now(),
+ Now = Mega * 1000000000 + Sec * 1000 + trunc(Micro / 1000) ,
+ ?debug("sched:calc_relative_tout(): TimeoutUnixMS(~p) - Now(~p) = ~p",
+ [ UnixTimeMS, Now, UnixTimeMS - Now ]),
- %%
- %% Slick but ugly.
- %% If the timeout is more than 24 hrs old when parsed as unix time,
- %% then we are looking at a relative msec timeout. Convert accordingly
- %%
- case UnixTime < Now - 86400 of
- true -> %% This is relative
- ?debug("sched:calc_relative_tout(): Timouet(~p) is relative in msec.",
- [ UnixTime ]),
- UnixTime;
+ %% Cap the timeout value at something reasonable
+ TOut = UnixTimeMS - Now,
+
+ case TOut =< 0 of
+ true ->
+ -1; %% We have timed out
false ->
- ?debug("sched:calc_relative_tout(): Timeout(~p) - Now(~p) = ~p",
- [ UnixTime, Now, UnixTime - Now ]),
-
- %% Cap the timeout value at something reasonable
- TOut =
- case UnixTime - Now >= 4294967295 of
- true ->
- ?info("sched:calc_relative_tout(): Timeout(~p) - Now(~p) = ~p: "
- "Truncated to 4294967295", [ UnixTime, Now, UnixTime - Now ]),
- 4294967295;
-
- false -> UnixTime - Now
- end,
-
- case TOut =< 0 of
- true ->
- -1; %% We have timed out
-
- false ->
- TOut * 1000 %% Convert to msec
- end
+ TOut
end.
-
%% Handle a callback for a timed out message.
do_timeout_callback(CompSpec, SvcName, TransID) ->
diff --git a/components/service_edge/src/service_edge_rpc.erl b/components/service_edge/src/service_edge_rpc.erl
index 9914bed..cff7fad 100644
--- a/components/service_edge/src/service_edge_rpc.erl
+++ b/components/service_edge/src/service_edge_rpc.erl
@@ -349,9 +349,9 @@ handle_call({rvi, get_available_services, []}, _From, St) ->
{reply, service_discovery_rpc:get_all_services(St#st.cs), St};
handle_call({ rvi, handle_local_message,
- [SvcName, Timeout, Parameters] }, _From, St) ->
+ [SvcName, TimeoutArg, Parameters] }, _From, St) ->
?debug("service_edge_rpc:local_msg: service_name: ~p", [SvcName]),
- ?debug("service_edge_rpc:local_msg: timeout: ~p", [Timeout]),
+ ?debug("service_edge_rpc:local_msg: timeout: ~p", [TimeoutArg]),
?debug("service_edge_rpc:local_msg: parameters: ~p", [Parameters]),
%%
@@ -362,7 +362,28 @@ handle_call({ rvi, handle_local_message,
[ok, Certificate, Signature ] =
authorize_rpc:authorize_local_message(St#st.cs, SvcName),
+ %%
+ %% Slick but ugly.
+ %% If the timeout is more than 24 hrs old when parsed as unix time,
+ %% then we are looking at a relative msec timeout. Convert accordingly
+ %%
+ { Mega, Sec, _Micro } = now(),
+ Now = Mega * 1000000 + Sec,
+
+ Timeout =
+ case TimeoutArg - Now < -86400 of
+ true -> %% Relative timeout arg. Convert to unix time msec
+ ?debug("service_edge_rpc:local_msg(): Timeout ~p is relative.",
+ [TimeoutArg]),
+ (Now * 1000) + TimeoutArg;
+
+ false -> %% Absolute timoeut. Convert to unix time msec
+ TimeoutArg * 1000
+ end,
+
+
+
%%
%% Check if this is a local service by trying to resolve its service name.
@@ -531,6 +552,7 @@ dispatch_to_local_service([ $w, $s, $: | WSPidStr], message,
wse:call(list_to_pid(WSPidStr), wse:window(),
"message",
[ "service_name", SvcName ] ++ flatten_ws_args(Args)),
+ ?debug("service_edge:dispatch_to_local_service(message, websock): Done", []),
ok;
%% Dispatch to regular JSON-RPC over HTTP.