Skip to content

Commit a94cacf

Browse files
committed
feat: use plugin helper
1 parent 9f2d43c commit a94cacf

File tree

12 files changed

+75
-95
lines changed

12 files changed

+75
-95
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ jobs:
2020
- name: Setup Erlang
2121
uses: erlef/setup-beam@v1
2222
with:
23-
otp-version: "26"
23+
otp-version: "27"
2424
rebar3-version: "3"
2525

26+
- name: Check format
27+
run: make fmt-check
28+
2629
- name: Start Dependencies
2730
run: make up
2831

@@ -49,7 +52,7 @@ jobs:
4952
- name: Setup Erlang
5053
uses: erlef/setup-beam@v1
5154
with:
52-
otp-version: "26"
55+
otp-version: "27"
5356
rebar3-version: "3"
5457

5558
- name: Build Release

Makefile

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
## to build emqtt without QUIC
12
export BUILD_WITHOUT_QUIC = 1
2-
export PROFILE = emqx
3-
## shallow clone for speed
4-
export REBAR_GIT_CLONE_OPTIONS += --depth=1
53

64
## Feature Used in rebar plugin emqx_plugrel
75
## The Feature have not enabled by default on OTP25
@@ -39,10 +37,6 @@ ct: $(REBAR) rel copy-plugin
3937
eunit: $(REBAR)
4038
$(REBAR) as test eunit
4139

42-
.PHONY: xref
43-
xref: $(REBAR)
44-
$(REBAR) xref
45-
4640
.PHONY: cover
4741
cover: $(REBAR)
4842
$(REBAR) cover
@@ -69,17 +63,11 @@ copy-plugin:
6963

7064
.PHONY: fmt
7165
fmt: $(REBAR)
72-
@find . \( -name '*.app.src' -o \
73-
-name '*.erl' -o \
74-
-name '*.hrl' -o \
75-
-name 'rebar.config' -o \
76-
-name '*.eterm' -o \
77-
-name '*.escript' \) \
78-
-not -path '*/_build/*' \
79-
-not -path '*/deps/*' \
80-
-not -path '*/_checkouts/*' \
81-
-type f \
82-
| xargs | $(REBAR) fmt --verbose -w
66+
$(REBAR) fmt --verbose -w
67+
68+
.PHONY: fmt-check
69+
fmt-check: $(REBAR)
70+
$(REBAR) fmt --verbose --check
8371

8472
.PHONY: up
8573
up:

rebar.config

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
%% -*- mode: erlang -*-
22
{deps, [
3-
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.44.0"}}},
4-
{typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}},
5-
{emqx, {git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx"}},
6-
{emqx_ctl, {git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_ctl"}},
7-
{emqx_utils,
8-
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_utils"}},
9-
{emqx_durable_storage,
10-
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"},
11-
"apps/emqx_durable_storage"}},
12-
{emqx_ds_backends,
13-
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_ds_backends"}},
14-
{emqx_ds_builtin_local,
15-
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"},
16-
"apps/emqx_ds_builtin_local"}}
3+
{emqx_plugin_helper,
4+
{git, "https://github.com/savonarola/emqx-plugin-helper.git", {branch, "main"}}}
175
]}.
186

197
{plugins, [
20-
{typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}},
21-
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.44.0"}}},
22-
{emqx_plugrel, {git, "https://github.com/emqx/emqx_plugrel.git", {tag, "0.5.0"}}},
23-
{erlfmt, "1.3.0"}
8+
{emqx_plugin_helper,
9+
{git, "https://github.com/savonarola/emqx-plugin-helper.git", {branch, "main"}}},
10+
{erlfmt, "1.6.0"}
2411
]}.
2512

2613
{profiles, [
@@ -39,11 +26,10 @@
3926
{relx, [
4027
{release,
4128
%% Do not update version manually, use make bump-version-patch/minor/major instead
42-
{emqx_offline_message_plugin, "1.0.1"},
43-
[
44-
emqx_offline_message_plugin
45-
]
46-
},
29+
{emqx_offline_message_plugin, "1.0.1"}, [
30+
emqx_offline_message_plugin,
31+
emqx_plugin_helper
32+
]},
4733
{dev_mode, false},
4834
{include_erts, false},
4935
{include_src, false}
@@ -62,12 +48,3 @@
6248
{compatibility, [{emqx, "~> 5.8"}]},
6349
{description, "Offline message persistence plugin for EMQX."}
6450
]}.
65-
66-
{xref_checks, [
67-
undefined_function_calls,
68-
undefined_functions,
69-
locals_not_used,
70-
deprecated_function_calls,
71-
warnings_as_errors,
72-
deprecated_functions
73-
]}.

scripts/ensure-rebar3.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ case ${OTP_VSN} in
1212
26*)
1313
VERSION="3.20.0-emqx-1"
1414
;;
15+
27*)
16+
VERSION="3.24.0-emqx-1"
17+
;;
1518
*)
1619
echo "Unsupported Erlang/OTP version $OTP_VSN"
1720
exit 1

src/emqx_offline_message_plugin_app.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
-module(emqx_offline_message_plugin_app).
66

7-
-include_lib("emqx/include/logger.hrl").
7+
-include_lib("emqx_plugin_helper/include/logger.hrl").
88

99
-behaviour(application).
1010

src/emqx_omp.erl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
-module(emqx_omp).
66

77
-include("emqx_omp.hrl").
8-
-include_lib("emqx/include/emqx.hrl").
9-
-include_lib("emqx/include/logger.hrl").
8+
-include_lib("emqx_plugin_helper/include/emqx.hrl").
9+
-include_lib("emqx_plugin_helper/include/logger.hrl").
1010

1111
-behaviour(gen_server).
1212

@@ -73,7 +73,9 @@ child_spec() ->
7373

7474
on_config_changed(OldConf, NewConf) ->
7575
try
76-
gen_server:call(?SERVER, #on_config_changed{old_conf = OldConf, new_conf = NewConf}, ?TIMEOUT)
76+
gen_server:call(
77+
?SERVER, #on_config_changed{old_conf = OldConf, new_conf = NewConf}, ?TIMEOUT
78+
)
7779
catch
7880
exit:{noproc, _} ->
7981
ok
@@ -162,14 +164,7 @@ status_to_error_list(ok) -> [];
162164
status_to_error_list({error, Error}) -> [Error].
163165

164166
current_config() ->
165-
case emqx_plugins:get_config(?PLUGIN_NAME_VSN) of
166-
%% Pre 5.9.0
167-
{ok, Config} when is_map(Config) ->
168-
Config;
169-
%% 5.9.0 and later
170-
Config when is_map(Config) ->
171-
Config
172-
end.
167+
emqx_plugin_helper:get_config(?PLUGIN_NAME).
173168

174169
init_metrics() ->
175170
?SLOG(info, #{msg => "omp_init_metrics"}),

src/emqx_omp_mysql.erl

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
-module(emqx_omp_mysql).
66

7-
-include_lib("emqx/include/emqx.hrl").
8-
-include_lib("emqx/include/logger.hrl").
9-
-include_lib("emqx/include/emqx_hooks.hrl").
7+
-include_lib("emqx_plugin_helper/include/emqx.hrl").
8+
-include_lib("emqx_plugin_helper/include/logger.hrl").
9+
-include_lib("emqx_plugin_helper/include/emqx_hooks.hrl").
1010

1111
-include("emqx_omp.hrl").
1212

@@ -29,7 +29,8 @@
2929
-define(TIMEOUT, 1000).
3030

3131
-define(INIT_SQL, [
32-
<<"CREATE TABLE IF NOT EXISTS `mqtt_msg` ("
32+
<<
33+
"CREATE TABLE IF NOT EXISTS `mqtt_msg` ("
3334
"`id` bigint unsigned NOT NULL AUTO_INCREMENT,"
3435
"`msgid` varchar(64) DEFAULT NULL,"
3536
"`topic` varchar(180) NOT NULL,"
@@ -40,15 +41,18 @@
4041
"`arrived` datetime NOT NULL,"
4142
"PRIMARY KEY (`id`),"
4243
"INDEX topic_index(`topic`)"
43-
")"
44-
"ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;">>,
44+
")"
45+
"ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;"
46+
>>,
4547

46-
<<"CREATE TABLE IF NOT EXISTS `mqtt_sub` ("
48+
<<
49+
"CREATE TABLE IF NOT EXISTS `mqtt_sub` ("
4750
"`clientid` varchar(64) NOT NULL,"
4851
"`topic` varchar(180) NOT NULL,"
4952
"`qos` tinyint(1) NOT NULL DEFAULT '0',"
5053
"PRIMARY KEY (`clientid`, `topic`)"
51-
") ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;">>
54+
") ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;"
55+
>>
5256
]).
5357

5458
-type statement() :: emqx_template_sql:statement().
@@ -100,7 +104,6 @@ start(ConfigRaw) ->
100104
{MysqlConfig, ResourceOpts} = make_mysql_resource_config(ConfigRaw),
101105
ok = start_resource(MysqlConfig, ResourceOpts),
102106

103-
104107
Statements = parse_statements(
105108
[delete_message_sql, select_message_sql, insert_subscription_sql, select_subscriptions_sql],
106109
ConfigRaw
@@ -410,18 +413,21 @@ init_default_schema(ConfigRaw) ->
410413
MysqlConfig,
411414
ResourceOpts
412415
),
413-
ok = lists:foreach(fun(Sql) ->
414-
case emqx_resource:simple_sync_query(?RESOURCE_ID_INIT, {sql, Sql, [], ?TIMEOUT}) of
415-
{error, Reason} ->
416-
?SLOG(error, #{
417-
msg => "omp_mysql_init_default_schema_error",
418-
sql => Sql,
419-
reason => Reason
420-
});
421-
_ ->
422-
ok
423-
end
424-
end, ?INIT_SQL),
416+
ok = lists:foreach(
417+
fun(Sql) ->
418+
case emqx_resource:simple_sync_query(?RESOURCE_ID_INIT, {sql, Sql, [], ?TIMEOUT}) of
419+
{error, Reason} ->
420+
?SLOG(error, #{
421+
msg => "omp_mysql_init_default_schema_error",
422+
sql => Sql,
423+
reason => Reason
424+
});
425+
_ ->
426+
ok
427+
end
428+
end,
429+
?INIT_SQL
430+
),
425431
ok = emqx_resource:remove_local(?RESOURCE_ID_INIT).
426432

427433
sync_query(Sql, Params) ->

src/emqx_omp_redis.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
-module(emqx_omp_redis).
66

7-
-include_lib("emqx/include/emqx.hrl").
8-
-include_lib("emqx/include/logger.hrl").
9-
-include_lib("emqx/include/emqx_hooks.hrl").
7+
-include_lib("emqx_plugin_helper/include/emqx.hrl").
8+
-include_lib("emqx_plugin_helper/include/logger.hrl").
9+
-include_lib("emqx_plugin_helper/include/emqx_hooks.hrl").
1010

1111
-include("emqx_omp.hrl").
1212

src/emqx_omp_utils.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
-module(emqx_omp_utils).
66

7-
-include_lib("emqx/include/logger.hrl").
7+
-include_lib("emqx_plugin_helper/include/logger.hrl").
88

99
-export([
1010
fix_ssl_config/1,
@@ -97,7 +97,13 @@ resource_health_status(Name, ResourceId) ->
9797
{ok, connected} ->
9898
ok;
9999
{ok, OtherStatus} ->
100-
{error, iolist_to_binary(io_lib:format("Resource ~s is not connected, status: ~p", [Name, OtherStatus]))};
100+
{error,
101+
iolist_to_binary(
102+
io_lib:format("Resource ~s is not connected, status: ~p", [Name, OtherStatus])
103+
)};
101104
{error, Reason} ->
102-
{error, iolist_to_binary(io_lib:format("Resource ~s health check failed: ~p", [Name, Reason]))}
103-
end.
105+
{error,
106+
iolist_to_binary(
107+
io_lib:format("Resource ~s health check failed: ~p", [Name, Reason])
108+
)}
109+
end.

test/emqx_omp_SUITE.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ set_server(redis_ssl, Config) ->
350350
emqx_utils_maps:deep_put([redis, servers], Config, <<"redis-ssl:6380">>).
351351

352352
unique_id() ->
353-
<<(emqx_guid:to_hexstr(emqx_guid:gen()))/binary>>.
353+
binary:encode_hex(crypto:strong_rand_bytes(16)).
354354

355355
unique_topic() ->
356356
<<"t/", (unique_id())/binary>>.

0 commit comments

Comments
 (0)