From 8543878a5560a7828c71629d1f81270e5dcfd811 Mon Sep 17 00:00:00 2001 From: Andrey Fadeev Date: Tue, 31 Mar 2020 16:37:41 +0300 Subject: [PATCH] Update snowflake (#133) --- rebar.lock | 2 +- src/woody_context.erl | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/rebar.lock b/rebar.lock index 28dcdc5..be003f1 100644 --- a/rebar.lock +++ b/rebar.lock @@ -29,7 +29,7 @@ {<<"ranch">>,{pkg,<<"ranch">>,<<"1.7.1">>},1}, {<<"snowflake">>, {git,"https://github.com/rbkmoney/snowflake.git", - {ref,"0a598108f6582affe3b4ae550fc5b9f2062e318a"}}, + {ref,"c34a962e17539e63a53f721cbf4ddcffeb0032a4"}}, 0}, {<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.5">>},1}, {<<"thrift">>, diff --git a/src/woody_context.erl b/src/woody_context.erl index c843f66..16e63ba 100644 --- a/src/woody_context.erl +++ b/src/woody_context.erl @@ -129,8 +129,17 @@ new_req_id() -> -spec new_unique_int() -> pos_integer(). new_unique_int() -> - <> = snowflake:new(?MODULE), - Id. + try snowflake:new(?MODULE) of + <> -> + Id + catch + error:{backward_clock_moving, _Last, _New} = Reason -> + BinReason = woody_error:format_details({snowflake, Reason}), + woody_error:raise(system, {internal, resource_unavailable, BinReason}); + error:exhausted = Reason -> + BinReason = woody_error:format_details({snowflake, Reason}), + woody_error:raise(system, {internal, resource_unavailable, BinReason}) + end. -spec set_deadline(woody:deadline(), ctx()) -> ctx().