Module z_module_manager

Module manager, starts/restarts a site's modules.

Copyright © 2009-2020 Marc Worrell

Behaviours: gen_server.

Authors: Marc Worrell (marc@worrell.nl).

Description

Module manager, starts/restarts a site's modules.

Data Types

manage_schema()

manage_schema() = install | {upgrade, integer()}

module_status()

module_status() = new | starting | running | stopping | restarting | retrying | failed | stopped | removing

Function Index

activate/2Activate a module.
activate_await/2
activate_precheck/2Before activating a module, check if it depends on non-activated other modules.
active/1Return the list of active modules.
active/2Return whether a specific module is active.
active_dir/1Return the list of all active modules and their directories.
all/1Return the list of all modules in the database.
code_change/3Convert process state when code is changed.
deactivate/2Deactivate a module.
deactivate_precheck/2Before deactivating a module, check if active modules depend on the deactivated module.
dependencies/1Return a module's dependencies as a tuple usable for z_toposort:sort/1.
dependency_sort/1Sort all modules on their dependencies (with sub sort the module's priority).
get_depending/0Return a table with per dependeny which modules depend on it.
get_modules/1Return the list of all modules running.
get_modules_status/1Return the status of all running modules.
get_provided/0Return a table with per provision which modules provide it.
get_provided/1Return the list of all provided functionalities in running modules.
get_upgrade_status/1Return the status of any ongoing upgrade.
handle_call/3Return a list of all modules.
handle_cast/2Sync enabled modules with loaded modules.
handle_info/2
init/1Initiates the server.
is_provided/2Check if a service is provided by any module.
lib_dir/1
module_exists/1Check if the code of a module exists.
module_reloaded/2Check all observers of a module, ensure that they are all active.
module_to_app/1
prio/1Return the priority of a module.
prio_sort/1Sort the results of a scan on module priority first, module name next.
reinstall/2Reinstall the given module's schema, calling Module:manage_schema(install, Context); if that function exists.
restart/2Restart a module, activates the module if it was not activated.
scan/0Scan for a list of modules.
start_link/1Starts the module manager.
startable/2
terminate/2This function is called by a gen_server when it is about to terminate.
title/1Get the title of a module.
upgrade/1Reload the list of all modules, add processes if necessary.
upgrade_await/1Wait till all modules are started, used when starting up a new or test site.
whereis/2Return the pid of a running module.

Function Details

activate/2

activate(Module::atom(), Context::z:context()) -> ok | {error, not_found}

Activate a module. The module is marked as active and started as a child of the module supervisor. The module manager can be checked later to see if the module started or not.

activate_await/2

activate_await(Module::atom(), Context::z:context()) -> ok | {error, not_active | not_found}

activate_precheck/2

activate_precheck(Module::atom() | [atom()], Context::z:context()) -> ok | {error, #{atom() => [atom()]}} | {error, {cyclic, z_toposort:cycles()}}

Before activating a module, check if it depends on non-activated other modules. This checks the complete graph of all modules that are currently activated plus the new modules. All missing dependencies will be listed. This also shows the modules that have missing dependencies and can't run because of those missing dependencies.

active/1

active(Context::#context{}) -> [Module::atom()]

Return the list of active modules.

active/2

active(Module::atom(), Context::#context{}) -> boolean()

Return whether a specific module is active.

active_dir/1

active_dir(Context::z:context()) -> [{Module::atom(), Dir::file:filename_all()}]

Return the list of all active modules and their directories

all/1

all(Context::z:context()) -> [atom()]

Return the list of all modules in the database.

code_change/3

code_change(OldVsn, State, Extra) -> {ok, NewState}

Convert process state when code is changed

deactivate/2

deactivate(Module::atom(), Context::z:context()) -> ok

Deactivate a module. The module is marked as deactivated and stopped when it was running.

deactivate_precheck/2

deactivate_precheck(Module::atom(), Context::z:context()) -> ok | {error, #{atom() => [atom()]}} | {error, {cyclic, z_toposort:cycles()}}

Before deactivating a module, check if active modules depend on the deactivated module. This checks the complete graph of all modules that are currently activated minus the deactivated module. All missing dependencies will be listed. This also shows the modules that have missing dependencies and can't run because of those missing dependencies.

dependencies/1

dependencies(M::{atom(), term()} | atom()) -> {atom() | {atom(), term()}, Depends::[atom()], Provides::[atom()]}

Return a module's dependencies as a tuple usable for z_toposort:sort/1.

dependency_sort/1

dependency_sort(Context::z:context() | [atom()]) -> {ok, [atom()]} | {error, {cyclic, z_toposort:cycles()}}

Sort all modules on their dependencies (with sub sort the module's priority)

get_depending/0

get_depending() -> #{atom() := [atom()]}

Return a table with per dependeny which modules depend on it.

get_modules/1

get_modules(Context) -> any()

Return the list of all modules running.

get_modules_status/1

get_modules_status(Context) -> any()

Return the status of all running modules.

get_provided/0

get_provided() -> #{atom() := [atom()]}

Return a table with per provision which modules provide it.

get_provided/1

get_provided(Context::z:context()) -> [atom()]

Return the list of all provided functionalities in running modules.

get_upgrade_status/1

get_upgrade_status(Context) -> any()

Return the status of any ongoing upgrade

handle_call/3

handle_call(Message::Request, From, State) -> {reply, Reply, State} | {reply, Reply, State, Timeout} | {noreply, State} | {noreply, State, Timeout} | {stop, Reason, Reply, State} | {stop, Reason, State}

Return a list of all modules

handle_cast/2

handle_cast(Message::Msg, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

Sync enabled modules with loaded modules

handle_info/2

handle_info(Info, State) -> {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}

init/1

init(Site::Args) -> {ok, State} | {ok, State, Timeout} | ignore | {stop, Reason}

Initiates the server.

is_provided/2

is_provided(Service::atom(), Context::z:context()) -> boolean()

Check if a service is provided by any module.

lib_dir/1

lib_dir(Module::atom()) -> {error, bad_name} | file:filename()

module_exists/1

module_exists(M) -> any()

Check if the code of a module exists. The database can hold module references to non-existing modules.

module_reloaded/2

module_reloaded(Module::atom(), Context::#context{}) -> ok

Check all observers of a module, ensure that they are all active. Used after a module has been reloaded

module_to_app/1

module_to_app(Module::atom()) -> atom()

prio/1

prio(Module::atom()) -> integer()

Return the priority of a module. Default priority is 500, lower is higher priority. Never crash on a missing module.

prio_sort/1

prio_sort(ModuleProps::[atom() | {atom(), term()}]) -> [atom() | {atom(), term()}]

Sort the results of a scan on module priority first, module name next. The list is made up of {module, Values} tuples

reinstall/2

reinstall(Module, Context) -> any()

Reinstall the given module's schema, calling Module:manage_schema(install, Context); if that function exists.

restart/2

restart(Module::atom(), Context::#context{}) -> ok | {error, not_found}

Restart a module, activates the module if it was not activated.

scan/0

scan() -> [{Module::atom(), Application::atom(), Dir::file:filename_all()}]

Scan for a list of modules. A module is always an OTP application, the name of the application is similar to the name of the module.

start_link/1

start_link(SiteProps::proplist()) -> {ok, Pid} | ignore | {error, Error}

Starts the module manager

startable/2

startable(M, Context) -> any()

terminate/2

terminate(Reason, State) -> void()

This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.

title/1

title(M) -> any()

Get the title of a module.

upgrade/1

upgrade(Context::z:context()) -> ok

Reload the list of all modules, add processes if necessary.

upgrade_await/1

upgrade_await(Context::z:context()) -> ok | {error, timeout}

Wait till all modules are started, used when starting up a new or test site.

whereis/2

whereis(Module::atom(), Context::z:context()) -> {ok, pid()} | {error, not_running | not_found}

Return the pid of a running module


Generated by EDoc