Skip to content

Commit

Permalink
Get rid of OS native timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
k32 committed Nov 13, 2018
1 parent 32a0761 commit 426b7d0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Kafka protocol library for Erlang/Elixir
Copyright 2014-2017 Klarna AB
Copyright 2014-2018 Klarna AB

This product includes software developed by
Klarna AB (https://www.klarna.com)
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@
- Add truely async send API `kpro:send/2`
* 2.2.2
- Moved make_ref to function impl from record definition

* 2.2.3
- Gotten rid of OS native timestamps
6 changes: 6 additions & 0 deletions include/kpro_private.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
-define(GET_STACKTRACE(Var), Var = erlang:get_stacktrace()).
-endif.

-ifndef(OLD_TIME_UNITS).
-define(millisecond, millisecond).
-else.
-define(millisecond, milli_seconds).
-endif.

-endif.

%%%_* Emacs ====================================================================
Expand Down
21 changes: 18 additions & 3 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
{_, ErlOpts} = lists:keyfind(erl_opts, 1, CONFIG).
Rel = try erlang:system_info(otp_release) of
Vsn ->
{match,[Maj]} = re:run(Vsn, "^R?([0-9]+)", [{capture,[1],list}]),
list_to_integer(Maj)
catch _:_ ->
"OLD"
end,
Macros = if Rel < 19 ->
[{d, 'OLD_TIME_UNITS'}];
true ->
[]
end,
CONFIG1 = lists:keystore(erl_opts, 1, CONFIG, {erl_opts, Macros ++ ErlOpts}),

IsRebar3 = erlang:function_exported(rebar3, main, 1),
case IsRebar3 of
true ->
CONFIG;
CONFIG1;
false ->
URLs = [ {snappyer, "https://github.com/zmstone/snappyer"}
, {crc32cer, "https://github.com/zmstone/crc32cer"}
],
Rebar3Deps = proplists:get_value(deps, CONFIG),
Rebar3Deps = proplists:get_value(deps, CONFIG1),
Rebar2Deps =
lists:map(
fun({Name, URL}) ->
Tag = proplists:get_value(Name, Rebar3Deps),
{Name, ".*", {git, URL, {tag, Tag}}}
end, URLs),
lists:keyreplace(deps, 1, CONFIG, {deps, Rebar2Deps})
lists:keyreplace(deps, 1, CONFIG1, {deps, Rebar2Deps})
end.
2 changes: 1 addition & 1 deletion src/kpro_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ get_ts_type(_, A) when ?KPRO_IS_APPEND_TS(A) -> append.

%% os:system_time(millisecond) is since otp 19
-spec now_ts() -> kpro:msg_ts().
now_ts() -> os:system_time() div 1000000.
now_ts() -> os:system_time(?millisecond).

-spec get_req_schema(kpro:api(), kpro:vsn()) -> kpro:struct_schema().
get_req_schema(Api, Vsn) ->
Expand Down
2 changes: 1 addition & 1 deletion src/kpro_sent_reqs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ scan_for_max_age(#requests{sent = Sent}) ->
next_corr_id(N) -> (N + 1) rem (1 bsl 31).

%% os:system_time('millisecond') is since otp-19
now_ts() -> os:system_time(1000).
now_ts() -> os:system_time(?millisecond).

%%%_* Emacs ====================================================================
%%% Local Variables:
Expand Down

0 comments on commit 426b7d0

Please sign in to comment.