bagofix
Test & Deploy to Snapdeploy / build-test-deploy (push) Failing after 24m46s

This commit is contained in:
2026-06-05 23:20:03 +03:00
parent 2497fe951b
commit 17b2e617d7
41 changed files with 365 additions and 194 deletions
+3 -2
View File
@@ -8,8 +8,9 @@
%%%-------------------------------------------------------------------
-spec save(#node_metric{}) -> ok.
save(Metric) ->
mnesia:dirty_write(Metric),
ok.
try mnesia:dirty_write(Metric)
catch _:_ -> ok
end.
%%%-------------------------------------------------------------------
%%% @doc Возвращает метрики за период, отсортированные по времени.
+18 -6
View File
@@ -269,15 +269,21 @@ apply_updates(Sub, Updates) ->
%%%-------------------------------------------------------------------
%%% @doc Разбор ISO8601 строки в формат `calendar:datetime()`.
%%% Поддерживает миллисекунды и таймзону.
%%% @end
%%%-------------------------------------------------------------------
-spec parse_iso_datetime(binary() | term()) -> calendar:datetime() | term().
parse_iso_datetime(Bin) when is_binary(Bin) ->
try
[DateStr, TimeStr] = string:split(Bin, "T"),
TimeStrNoZ = string:trim(TimeStr, trailing, "Z"),
[YearStr, MonthStr, DayStr] = string:split(DateStr, "-", all),
[HourStr, MinuteStr, SecondStr] = string:split(TimeStrNoZ, ":", all),
[DatePart, TimePart] = string:split(Bin, "T"),
[YearStr, MonthStr, DayStr] = string:split(DatePart, "-", all),
TimeNoZ = string:trim(TimePart, trailing, "Z"),
[HourStr, MinuteStr, SecondPart] = string:split(TimeNoZ, ":", all),
% удаляем миллисекунды, если они есть
SecondStr = case string:split(SecondPart, ".") of
[Sec, _] -> Sec;
_ -> SecondPart
end,
Year = binary_to_integer(list_to_binary(YearStr)),
Month = binary_to_integer(list_to_binary(MonthStr)),
Day = binary_to_integer(list_to_binary(DayStr)),
@@ -357,6 +363,7 @@ count_trial_subscriptions() ->
%%%-------------------------------------------------------------------
%%% @doc Платные подписки (trial_used = true), истекающие в течение Days дней.
%%% Принимает меры к преобразованию expires_at, если оно сохранено как строка.
%%% @end
%%%-------------------------------------------------------------------
-spec get_ending_paid_subscriptions(Days :: non_neg_integer()) -> [#subscription{}].
@@ -366,6 +373,11 @@ get_ending_paid_subscriptions(Days) ->
Match = #subscription{status = active, trial_used = true, _ = '_'},
ActivePaid = mnesia:dirty_match_object(Match),
lists:filter(fun(#subscription{expires_at = Exp}) ->
ExpSec = calendar:datetime_to_gregorian_seconds(Exp),
ExpDateTime = case Exp of
{{_,_,_}, {_,_,_}} -> Exp; % уже datetime
Bin when is_binary(Bin) -> parse_iso_datetime(Bin);
_ -> Exp
end,
ExpSec = calendar:datetime_to_gregorian_seconds(ExpDateTime),
ExpSec >= NowSec andalso ExpSec =< ThresholdSec
end, ActivePaid).
end, ActivePaid).