chore: remove unnecessary repeated code
Co-authored-by: Zaiming (Stone) Shi <zmstone@gmail.com>
This commit is contained in:
parent
05032467bd
commit
402ab7e759
|
@ -19,16 +19,8 @@
|
|||
-include_lib("typerefl/include/types.hrl").
|
||||
-include_lib("hocon/include/hoconsc.hrl").
|
||||
|
||||
-type duration_ms() :: integer().
|
||||
|
||||
-typerefl_from_string({duration_ms/0, emqx_schema, to_duration_ms}).
|
||||
|
||||
-behaviour(hocon_schema).
|
||||
|
||||
-reflect_type([
|
||||
duration_ms/0
|
||||
]).
|
||||
|
||||
-export([
|
||||
namespace/0,
|
||||
roots/0,
|
||||
|
@ -38,11 +30,6 @@
|
|||
|
||||
-export([validate_sql/1, validate_rule_name/1]).
|
||||
|
||||
% workaround: prevent being recognized as unused functions
|
||||
-export([
|
||||
to_duration_ms/1
|
||||
]).
|
||||
|
||||
namespace() -> rule_engine.
|
||||
|
||||
roots() -> ["rule_engine"].
|
||||
|
@ -57,7 +44,7 @@ fields("rule_engine") ->
|
|||
})},
|
||||
{jq_function_default_timeout,
|
||||
sc(
|
||||
duration_ms(),
|
||||
emqx_schema:duration_ms(),
|
||||
#{
|
||||
default => "10s",
|
||||
desc => ?DESC("rule_engine_jq_function_default_timeout")
|
||||
|
@ -239,20 +226,3 @@ validate_sql(Sql) ->
|
|||
|
||||
sc(Type, Meta) -> hoconsc:mk(Type, Meta).
|
||||
ref(Field) -> hoconsc:ref(?MODULE, Field).
|
||||
|
||||
-spec ceiling(number()) -> integer().
|
||||
ceiling(X) ->
|
||||
T = erlang:trunc(X),
|
||||
case (X - T) of
|
||||
Neg when Neg < 0 -> T;
|
||||
Pos when Pos > 0 -> T + 1;
|
||||
_ -> T
|
||||
end.
|
||||
|
||||
-spec to_duration_ms(Input) -> {ok, integer()} | {error, Input} when
|
||||
Input :: string() | binary().
|
||||
to_duration_ms(Str) ->
|
||||
case hocon_postprocess:duration(Str) of
|
||||
I when is_number(I) -> {ok, ceiling(I)};
|
||||
_ -> {error, Str}
|
||||
end.
|
||||
|
|
2
mix.exs
2
mix.exs
|
@ -611,7 +611,7 @@ defmodule EMQXUmbrella.MixProject do
|
|||
|
||||
defp jq_dep() do
|
||||
if enable_jq?(),
|
||||
do: [{:jq, github: "emqx/jq", tag: "v0.3.0-beta.1", override: true}],
|
||||
do: [{:jq, github: "emqx/jq", tag: "v0.3.0", override: true}],
|
||||
else: []
|
||||
end
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ quicer() ->
|
|||
{quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.9"}}}.
|
||||
|
||||
jq() ->
|
||||
{jq, {git, "https://github.com/emqx/jq", {tag, "v0.3.0-beta.1"}}}.
|
||||
{jq, {git, "https://github.com/emqx/jq", {tag, "v0.3.0"}}}.
|
||||
|
||||
deps(Config) ->
|
||||
{deps, OldDeps} = lists:keyfind(deps, 1, Config),
|
||||
|
|
Loading…
Reference in New Issue