z_module_manager (zotonic_core v1.0.0-rc.12)

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

Link to this section Summary

Functions

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.
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.
Return the list of active modules.
Return whether a specific module is active.
Return the list of all active modules and their directories
Return the list of all modules in the database.
Convert process state when code is changed
Deactivate a module. The module is marked as deactivated and stopped when it was running.
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.
Return a module's dependencies as a tuple usable for z_toposort:sort/1.
Sort all modules on their dependencies (with sub sort the module's priority)
Return the list of all modules running.
Return the status of all running modules.
Return the list of all provided functionalities in running modules.
Return the status of any ongoing upgrade
Return a list of all modules
Sync enabled modules with loaded modules
Initiates the server.
Check if a service is provided by any module.
Check if the code of a module exists. The database can hold module references to non-existing modules.
Check all observers of a module, ensure that they are all active. Used after a module has been reloaded
Return the priority of a module. Default priority is 500, lower is higher priority. Never crash on a missing module.
Sort the results of a scan on module priority first, module name next. The list is made up of {module, Values} tuples
Reinstall the given module's schema, calling Module:manage_schema(install, Context); if that function exists.
Restart a module, activates the module if it was not activated.
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.
Scan for a list of modules and the current site. A module is always an OTP application,
Return a table with per dependeny which modules depend on it.
Return a table with per provision which modules provide it.
Starts the module manager
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.
Get the title of a module.
Reload the list of all modules, add processes if necessary.
Wait till all modules are started, used when starting up a new or test site.
Return the pid of a running module

Link to this section Types

Link to this type

manage_schema/0

-type manage_schema() :: install | {upgrade, integer()}.
Link to this type

module_status/0

-type module_status() ::
    new | starting | running | stopping | restarting | retrying | failed | stopped | removing.

Link to this section Functions

Link to this function

activate(Module, Context)

-spec activate(atom(), 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.
Link to this function

activate_await(Module, Context)

-spec activate_await(atom(), z:context()) -> ok | {error, not_active | not_found}.
Link to this function

activate_precheck(Module, Context)

-spec activate_precheck(atom() | [atom()], 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.
Link to this function

active(Context)

-spec active(#context{}) -> [Module :: atom()].
Return the list of active modules.
Link to this function

active(Module, Context)

-spec active(Module :: atom(), #context{}) -> boolean().
Return whether a specific module is active.
Link to this function

active_dir(Context)

-spec active_dir(z:context()) -> [{Module :: atom(), Dir :: file:filename_all()}].
Return the list of all active modules and their directories
-spec all(z:context()) -> [atom()].
Return the list of all modules in the database.
Link to this function

code_change(OldVsn, State, Extra)

Convert process state when code is changed
Link to this function

deactivate(Module, Context)

-spec deactivate(atom(), z:context()) -> ok.
Deactivate a module. The module is marked as deactivated and stopped when it was running.
Link to this function

deactivate_precheck(Module, Context)

-spec deactivate_precheck(atom(), 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.
Link to this function

dependencies(M)

-spec dependencies({atom(), term()} | atom()) ->
                {atom() | {atom(), term()}, Depends :: [atom()], Provides :: [atom()]}.
Return a module's dependencies as a tuple usable for z_toposort:sort/1.
Link to this function

dependency_sort(Context)

-spec dependency_sort(z:context() | [atom()]) -> {ok, [atom()]} | {error, {cyclic, z_toposort:cycles()}}.
Sort all modules on their dependencies (with sub sort the module's priority)
Link to this function

get_modules(Context)

Return the list of all modules running.
Link to this function

get_modules_status(Context)

Return the status of all running modules.
Link to this function

get_provided(Context)

-spec get_provided(z:context()) -> [atom()].
Return the list of all provided functionalities in running modules.
Link to this function

get_upgrade_status(Context)

Return the status of any ongoing upgrade
Link to this function

handle_call(Message, From, State)

Return a list of all modules
Link to this function

handle_cast(Message, State)

Sync enabled modules with loaded modules
Link to this function

handle_info(Info, State)

Initiates the server.
Link to this function

is_provided(Service, Context)

-spec is_provided(atom(), z:context()) -> boolean().
Check if a service is provided by any module.
Link to this function

lib_dir(Module)

-spec lib_dir(atom()) -> {error, bad_name} | file:filename().
Link to this function

module_exists(M)

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

module_reloaded(Module, Context)

-spec module_reloaded(Module :: atom(), #context{}) -> ok.
Check all observers of a module, ensure that they are all active. Used after a module has been reloaded
Link to this function

module_to_app(Module)

-spec module_to_app(atom()) -> atom().
-spec prio(atom()) -> integer().
Return the priority of a module. Default priority is 500, lower is higher priority. Never crash on a missing module.
Link to this function

prio_sort(ModuleProps)

-spec prio_sort([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
Link to this function

reinstall(Module, Context)

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

restart(Module, Context)

-spec restart(Module :: atom(), #context{}) -> ok | {error, not_found}.
Restart a module, activates the module if it was not activated.
-spec 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.
-spec scan(z:context()) -> [{Module :: atom(), Application :: atom(), Dir :: file:filename_all()}].
Scan for a list of modules and the current site. A module is always an OTP application,
Link to this function

scan_depending(Context)

-spec scan_depending(z:context()) -> #{atom() := [atom()]}.
Return a table with per dependeny which modules depend on it.
Link to this function

scan_provided(Context)

-spec scan_provided(z:context()) -> #{atom() := [atom()]}.
Return a table with per provision which modules provide it.
Link to this function

start_link(Site)

Starts the module manager
Link to this function

startable(M, Context)

Link to this function

terminate(Reason, State)

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.
Get the title of a module.
Link to this function

upgrade(Context)

-spec upgrade(z:context()) -> ok.
Reload the list of all modules, add processes if necessary.
Link to this function

upgrade_await(Context)

-spec upgrade_await(z:context()) -> ok | {error, timeout}.
Wait till all modules are started, used when starting up a new or test site.
Link to this function

whereis(Module, Context)

-spec whereis(atom(), z:context()) -> {ok, pid()} | {error, not_running | not_found}.
Return the pid of a running module