emqx_resource.hrl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2022 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -type resource_type() :: module().
  17. -type instance_id() :: binary().
  18. -type raw_resource_config() :: binary() | raw_term_resource_config().
  19. -type raw_term_resource_config() :: #{binary() => term()} | [raw_term_resource_config()].
  20. -type resource_config() :: term().
  21. -type resource_spec() :: map().
  22. -type resource_state() :: term().
  23. -type resource_data() :: #{
  24. id := instance_id(),
  25. mod := module(),
  26. config := resource_config(),
  27. state := resource_state(),
  28. status := started | stopped | starting,
  29. metrics := emqx_plugin_libs_metrics:metrics()
  30. }.
  31. -type resource_group() :: binary().
  32. -type create_opts() :: #{
  33. %% The emqx_resource:create/4 will return OK event if the Mod:on_start/2 fails,
  34. %% the 'status' of the resource will be 'stopped' in this case.
  35. %% Defaults to 'false'
  36. async_create => boolean()
  37. }.
  38. -type after_query() :: {[OnSuccess :: after_query_fun()], [OnFailed :: after_query_fun()]} |
  39. undefined.
  40. %% the `after_query_fun()` is mainly for callbacks that increment counters or do some fallback
  41. %% actions upon query failure
  42. -type after_query_fun() :: {fun((...) -> ok), Args :: [term()]}.
  43. -define(TEST_ID_PREFIX, "_test_:").