Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{elvis_style, macro_module_names},
{elvis_style, operator_spaces, #{rules => [{right, ","}, {right, "++"}, {left, "++"}]}},
{elvis_style, nesting_level, #{level => 4}},
{elvis_style, no_if_expression},
{elvis_style, no_if_expression, #{ignore => [prg_pg_backend, prg_utils]}},
%% FIXME Implement appropriate behaviours
{elvis_style, invalid_dynamic_call, #{
ignore => [prg_storage, prg_worker_sidecar]
Expand Down
22 changes: 13 additions & 9 deletions include/progressor.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
last_event_id => event_id(),
initialization => task_id(),
previous_status => process_status(),
status_changed_at => timestamp_sec()
status_changed_at => timestamp_us()
}.

-type task() :: #{
task_id => task_id(),
process_id := id(),
task_type := task_type(),
status := task_status(),
scheduled_time := timestamp_sec(),
running_time => timestamp_sec(),
finished_time => timestamp_sec(),
scheduled_time := timestamp_us(),
running_time => timestamp_us(),
finished_time => timestamp_us(),
args => binary(),
metadata => map(),
idempotency_key => binary(),
Expand All @@ -59,11 +59,12 @@
task_id := task_id(),
task_type := task_type(),
task_status := task_status(),
scheduled := timestamp_sec(),
running => timestamp_sec(),
finished => timestamp_sec(),
scheduled := timestamp_us(),
running => timestamp_us(),
finished => timestamp_us(),
args => binary(),
metadata => map(),
context => binary(),
idempotency_key => binary(),
response => term(),
retry_interval => non_neg_integer(),
Expand Down Expand Up @@ -190,10 +191,13 @@
-type task_result() :: #{
task_id := task_id(),
status := task_status(),
running_time => timestamp_sec(),
finished_time => timestamp_sec(),
response => binary()
}.

%% microsecond
-type timestamp_us() :: non_neg_integer().
-type timestamp_ms() :: non_neg_integer().
-type timestamp_sec() :: non_neg_integer().
-type timeout_sec() :: non_neg_integer().
Expand Down Expand Up @@ -221,6 +225,6 @@
process_id => ProcessId,
status => <<"init">>,
previous_status => <<"init">>,
created_at => erlang:system_time(second),
status_changed_at => erlang:system_time(second)
created_at => erlang:system_time(microsecond),
status_changed_at => erlang:system_time(microsecond)
}).
34 changes: 34 additions & 0 deletions src/prg_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
-export([make_ns_opts/2]).
-export([unixtime_to_datetime/1]).
-export([with_observe/4]).
-export([to_microseconds/1]).
-export([to_seconds/1]).
-export([with_observe/5]).
-export([with_span/2]).

Expand Down Expand Up @@ -91,3 +93,35 @@ collect(histogram, MetricKey, Labels, Value) ->
%%collect(_, _MetricKey, _Labels, _Value) ->
%% %% TODO implement it
%% ok.

-spec to_microseconds(non_neg_integer()) -> non_neg_integer() | no_return().
to_microseconds(Timestamp) ->
if
Timestamp < 100000000000 ->
%% seconds
Timestamp * 1000000;
Timestamp < 100000000000000 ->
%% milliseconds
Timestamp * 1000;
Timestamp < 100000000000000000 ->
%% microseconds
Timestamp;
true ->
error({unsupported_time_unit, Timestamp})
end.

-spec to_seconds(non_neg_integer()) -> non_neg_integer() | no_return().
to_seconds(Timestamp) ->
if
Timestamp < 100000000000 ->
%% seconds
Timestamp;
Timestamp < 100000000000000 ->
%% milliseconds
Timestamp div 1000;
Timestamp < 100000000000000000 ->
%% microseconds
Timestamp div 1000000;
true ->
error({unsupported_time_unit, Timestamp})
end.
Loading
Loading