### Start HighlanderPG in Supervision Tree Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Wrap your supervisor or process with HighlanderPG to ensure it runs as a singleton. This example shows how to include it in your application's children list. ```elixir # lib/application.ex children = [ ... {HighlanderPG, [child: MyChild, repo: MyApp.Repo]}, ... ] Supervisor.init(children, strategy: :one_for_one) ``` -------------------------------- ### Start HighlanderPG with Options Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html This function signature indicates how to start HighlanderPG, typically within a supervision tree. It accepts a list of start options to configure its behavior. ```elixir @spec start_link([start_opt()]) :: Supervisor.on_start() ``` -------------------------------- ### Define HighlanderPG Start Options Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html This type definition outlines the various options available when starting HighlanderPG, such as specifying the child process, connection options, repository module, and names. ```elixir @type start_opt() :: {:child, Supervisor.child_spec()} | {:connect_opts, keyword()} | {:repo, module()} | {:name, term()} | {:sup_name, term()} | {:polling_interval, integer()} ``` -------------------------------- ### HighlanderPG Supervisor Integration Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Demonstrates how to start HighlanderPG as a child process within a Supervisor, specifying required and optional configuration options. ```APIDOC ## HighlanderPG Supervisor Integration ### Description HighlanderPG can be supervised by starting it as a child in your application's Supervisor. This involves providing a child specification that includes the HighlanderPG module and a list of options. ### Options * `:child` - Mandatory. The child spec of the process or supervisor that HighlanderPG will run. * `:connect_opts` - Optional. These are passed to `Postgrex.SimpleConnection.start_link/3`. See `Postgrex.start_link/1` for relevant options. * `:repo` - Optional (one of `:connect_opts` or `:repo` must be specified). Your Ecto Repo. Highlander will use this to create a new connection for the advisory lock. * `:sup_name` - Optional. A name for HighlanderPG's process, allowing easy access later. * `:polling_interval` - Optional. Configures HighlanderPG's polling interval in milliseconds. Defaults to 300. * `:name` - Optional. The key on which HighlanderPG ensures your supervised process or supervisor is unique. Defaults to `HighlanderPG`. ### Example Usage ```elixir # Example with basic options my_child = {MyUniqueProcess, arg} children = [ ... {HighlanderPG, [child: my_child, repo: MyApp.Repo]} ... ] Supervisor.init(children, strategy: :one_for_one) ``` ```elixir # Example with all options specified children = [ {HighlanderPG, [child: child, connect_opts: connect_opts, repo: repo, sup_name: :my_highlander, polling_interval: 100]} ] ``` ```elixir # Example for monitoring multiple unique processes children = [ {HighlanderPG, [child: child1, repo: repo, name: :highlander1]}, {HighlanderPG, [child: child2, repo: repo, name: :highlander2]}, ] ``` ``` -------------------------------- ### HighlanderPG Usage Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Example of how to integrate HighlanderPG into your application's supervision tree. ```APIDOC ## Usage Wrap your supervisor or process with HighlanderPG and it will ensure that it only runs on one node in your cluster. ```elixir # lib/application.ex children = [ ..., {HighlanderPG, [child: MyChild, repo: MyApp.Repo]}, ... ] Supervisor.init(children, strategy: :one_for_one) ``` ``` -------------------------------- ### Getting Supervisor Child Information Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html The `HighlanderPG.which_children/1` function is an alias for `Supervisor.which_children/1`, providing details about the children managed by a supervisor. ```elixir @spec which_children(Supervisor.supervisor()) :: [ {term() | :undefined, Supervisor.child(), :worker | :supervisor, [module()] | :dynamic} ] See `Supervisor.which_children/1`. ``` -------------------------------- ### Add HighlanderPG to Mix Dependencies Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Include highlander_pg in your project's dependencies in mix.exs to manage its installation and updates. ```elixir def deps do [ {:highlander_pg, "~> 1.0"}, ] end ``` -------------------------------- ### Get Child Process Count Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Use the count_children function to retrieve the number of specs, active processes, supervisors, and workers within the HighlanderPG supervisor. This is useful for monitoring and debugging. ```elixir @spec count_children(Supervisor.supervisor()) :: %{ specs: non_neg_integer(), active: non_neg_integer(), supervisors: non_neg_integer(), workers: non_neg_integer() } ``` -------------------------------- ### Monitoring HighlanderPG Child Count Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Use `HighlanderPG.count_children/1` to get a status report of active children managed by HighlanderPG. This function requires the supervisor name. ```elixir HighlanderPG.count_children(:my_highlander) #=> %{active: 1, workers: 1, supervisors: 0, specs: 1} ``` -------------------------------- ### Configuring HighlanderPG with Options Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Customize HighlanderPG's behavior using options like `:connect_opts` for database connection, `:repo` for Ecto integration, `:sup_name` for process naming, and `:polling_interval` for frequency. ```elixir children = [ {HighlanderPG, [child: child, connect_opts: connect_opts, repo: repo, sup_name: :my_highlander, polling_interval: 100]} ] ``` -------------------------------- ### Define Global Singleton Process Name Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Use Erlang's :global module to assign a global name to your GenServer, allowing it to be found and communicated with across the cluster. ```elixir # GenServer.start_link GenServer.start_link(MyGenServer, args, name: {:global, "my_global_name"}) # child_spec %{ id: MyGenServer, start: {GenServer, :start_link, [MyGenServer, args, name: {:global, "my_global_name"}]} } ``` -------------------------------- ### Supervising a Child Process with HighlanderPG Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Configure HighlanderPG as a child in your application's supervisor. The `:child` option specifies the process or supervisor to run, and `:repo` or `:connect_opts` are required for database connection. ```elixir my_child = {MyUniqueProcess, arg} children = [ ... {HighlanderPG, [child: my_child, repo: MyApp.Repo]} ... ] Supervisor.init(children, strategy: :one_for_one) ``` -------------------------------- ### HighlanderPG Functions Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Available functions for interacting with HighlanderPG. ```APIDOC ## Functions ### `child_spec(init_arg)` Returns a specification to start this module under a supervisor. See `Supervisor`. ### `count_children(server)` ```elixir @spec count_children(Supervisor.supervisor()) :: %{ specs: non_neg_integer(), active: non_neg_integer(), supervisors: non_neg_integer(), workers: non_neg_integer() } ``` See `Supervisor.count_children/1`. ### `start_link(opts)` ```elixir @spec start_link([start_opt()]) :: Supervisor.on_start() ``` Starts HighlanderPG. This function is normally not called directly. You would incorporate HighlanderPG in your supervision tree as follows: ```elixir # Example usage within a supervision tree children = [ {HighlanderPG, [child: MyChild, repo: MyApp.Repo]} ] ``` ### `which_children(server)` See `Supervisor.which_children/1`. ``` -------------------------------- ### Ensuring Unique Processes with Named HighlanderPG Instances Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Assign a unique `:name` to each HighlanderPG instance when supervising multiple globally unique processes. This allows HighlanderPG to differentiate and manage them independently. ```elixir children = [ {HighlanderPG, [child: child1, repo: repo, name: :highlander1]}, {HighlanderPG, [child: child2, repo: repo, name: :highlander2]}, ] ``` -------------------------------- ### HighlanderPG.which_children/1 Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Returns a list of child specifications for a given HighlanderPG supervised process, similar to `Supervisor.which_children/1`. ```APIDOC ## HighlanderPG.which_children/1 ### Description This function mirrors the behavior of `Supervisor.which_children/1`, providing detailed information about the children managed by a HighlanderPG supervisor. ### Method `HighlanderPG.which_children/1` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir HighlanderPG.which_children(:my_highlander) ``` ### Response #### Success Response (200) - `list()` - A list of tuples, where each tuple contains the child's name, its specification, its type (worker or supervisor), and its module list or `:dynamic`. ### Response Example ```elixir [ {:my_child_name, {MyUniqueProcess, arg}, :worker, [MyUniqueProcess]}, ... ] ``` ``` -------------------------------- ### HighlanderPG Types Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Type specifications for HighlanderPG options. ```APIDOC # Types ## `start_opt()` ```elixir @type start_opt() :: {:child, Supervisor.child_spec()} | {:connect_opts, keyword()} | {:repo, module()} | {:name, term()} | {:sup_name, term()} | {:polling_interval, integer()} ``` ``` -------------------------------- ### HighlanderPG.count_children/1 Source: https://hexdocs.pm/highlander_pg/1.0.8/HighlanderPG.html Retrieves the current count of active children, workers, supervisors, and specs managed by a HighlanderPG instance. ```APIDOC ## HighlanderPG.count_children/1 ### Description This function returns a map containing the counts of active children, workers, supervisors, and specs for a given HighlanderPG supervised process. ### Method `HighlanderPG.count_children/1` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir HighlanderPG.count_children(:my_highlander) ``` ### Response #### Success Response (200) - `map()` - A map with keys `:active`, `:workers`, `:supervisors`, and `:specs`. #### Response Example ```json { "active": 1, "workers": 1, "supervisors": 0, "specs": 1 } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.