| 1 |
|
%% Copyright (c) 2022 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(pgec_config). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([http/1]). |
| 20 |
|
-export([leveled/1]). |
| 21 |
|
-export([sup_flags/1]). |
| 22 |
|
-export([telemetry/1]). |
| 23 |
|
-export([timeout/1]). |
| 24 |
|
-import(envy, [envy/1]). |
| 25 |
|
|
| 26 |
|
|
| 27 |
|
sup_flags(Supervisor) -> |
| 28 |
8 |
lists:foldl( |
| 29 |
|
fun |
| 30 |
|
(Name, A) -> |
| 31 |
16 |
A#{Name => restart(Supervisor, Name)} |
| 32 |
|
end, |
| 33 |
|
#{}, |
| 34 |
|
[intensity, period]). |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
restart(Supervisor, Name) when Name == intensity; Name == period -> |
| 38 |
16 |
envy(#{caller => ?MODULE, |
| 39 |
|
names => [Supervisor, ?FUNCTION_NAME, Name], |
| 40 |
|
default => restart(Name)}). |
| 41 |
|
|
| 42 |
|
restart(intensity) -> |
| 43 |
8 |
1; |
| 44 |
|
restart(period) -> |
| 45 |
8 |
5. |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
timeout(no_members = Name) -> |
| 49 |
:-( |
envy(#{caller => ?MODULE, |
| 50 |
|
type => integer_or_atom, |
| 51 |
|
names => [Name, timeout], |
| 52 |
|
default => timer:seconds(1)}); |
| 53 |
|
|
| 54 |
|
timeout(expiry = Name) -> |
| 55 |
392 |
envy(#{caller => ?MODULE, |
| 56 |
|
type => integer_or_atom, |
| 57 |
|
names => [Name, timeout], |
| 58 |
|
default => timer:minutes(5)}); |
| 59 |
|
|
| 60 |
|
timeout(Name) -> |
| 61 |
:-( |
envy(#{caller => ?MODULE, |
| 62 |
|
type => integer_or_atom, |
| 63 |
|
names => [Name, timeout], |
| 64 |
|
default => infinity}). |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
http(port = Name) -> |
| 68 |
8 |
envy(#{caller => ?MODULE, |
| 69 |
|
names => [?FUNCTION_NAME, Name], |
| 70 |
|
default => 80}). |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
telemetry(Name) when Name == module; Name == function -> |
| 74 |
8 |
envy(#{caller => ?MODULE, |
| 75 |
|
type => atom, |
| 76 |
|
names =>[?FUNCTION_NAME, Name]}); |
| 77 |
|
|
| 78 |
|
telemetry(event_names = Name) -> |
| 79 |
:-( |
envy(#{caller => ?MODULE, |
| 80 |
|
names => [?FUNCTION_NAME, Name], |
| 81 |
|
default => filename:join(pgec:priv_dir(), "telemetry.terms")}); |
| 82 |
|
|
| 83 |
|
telemetry(config = Name) -> |
| 84 |
:-( |
envy:get_env(pgec, |
| 85 |
|
pgmp_util:snake_case([?FUNCTION_NAME, Name]), |
| 86 |
|
[app_env, {default, []}]). |
| 87 |
|
|
| 88 |
|
|
| 89 |
|
leveled(root_path = Name) -> |
| 90 |
8 |
envy(#{caller => ?MODULE, |
| 91 |
|
names => [?FUNCTION_NAME, Name], |
| 92 |
|
default => "/data"}); |
| 93 |
|
|
| 94 |
|
leveled(log_level = Name) -> |
| 95 |
8 |
envy(#{caller => ?MODULE, |
| 96 |
|
names => [?FUNCTION_NAME, Name], |
| 97 |
|
default => warn}). |