z_module_manager (zotonic_core v1.0.0-rc.17)
Module manager, starts/restarts a site's modules.
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. Exclude modules that are missing from the system.
Check which modules are active and installed but currently not in running state. The site is hardcoded as it must be part of the running list of modules, if not then it is added to the list of not running modules irrespective if it is activated or not.
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)
List of modules enabled for backup sites.
Return the list of all modules running.
Return the status of all enabled modules.
Return the list of all provided functionalities in running modules.
Return the list of all modules that are activated but not present on the file system.
Return the status of any ongoing upgrade
Return a list of all modules
Sync enabled modules with loaded modules
Handle down messages from modules.
Initiates the server.
Check if a service is provided by any module.
Get the author of a module.
Get the configurations of a module.
Get the description of a module.
Fetch information about a module or site.
Get the schema version of a module.
Get the title of a 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.
Run after a site has been started up. Notify to the site that all modules are ready and load the translations.
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.
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
Types
-type manage_schema() :: install | {upgrade, ToVersion :: integer()}.
-type module_status() ::
new | starting | running | stopping | restarting | retrying | failed | stopped | removing.
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.
-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.
-spec active(#context{cowreq :: cowboy_req:req() | undefined, cowenv :: cowboy_middleware:env() | undefined, site :: atom(), controller_module :: atom() | undefined, client_id :: binary() | undefined, client_topic :: mqtt_sessions:topic() | undefined, routing_id :: binary() | undefined, acl :: term() | admin | undefined, acl_is_read_only :: boolean(), user_id :: integer() | authenticated | undefined, render_state :: undefined | z_render:render_state(), db :: {atom(), atom()} | undefined, dbc :: pid() | undefined, language :: [atom()], tz :: binary(), props :: map(), depcache :: pid() | atom(), dispatcher :: pid() | atom(), template_server :: pid() | atom(), scomp_server :: pid() | atom(), dropbox_server :: pid() | atom(), pivot_server :: pid() | atom(), module_indexer :: pid() | atom(), translation_table :: atom()}) -> [Module :: atom()].
Return the list of active modules.
-spec active(Module :: atom(), #context{cowreq :: cowboy_req:req() | undefined, cowenv :: cowboy_middleware:env() | undefined, site :: atom(), controller_module :: atom() | undefined, client_id :: binary() | undefined, client_topic :: mqtt_sessions:topic() | undefined, routing_id :: binary() | undefined, acl :: term() | admin | undefined, acl_is_read_only :: boolean(), user_id :: integer() | authenticated | undefined, render_state :: undefined | z_render:render_state(), db :: {atom(), atom()} | undefined, dbc :: pid() | undefined, language :: [atom()], tz :: binary(), props :: map(), depcache :: pid() | atom(), dispatcher :: pid() | atom(), template_server :: pid() | atom(), scomp_server :: pid() | atom(), dropbox_server :: pid() | atom(), pivot_server :: pid() | atom(), module_indexer :: pid() | atom(), translation_table :: atom()}) -> boolean().
Return whether a specific module is active.
-spec active_dir(z:context()) -> [{Module :: atom(), Dir :: file:filename_all()}].
Return the list of all active modules and their directories. Exclude modules that are missing from the system.
Check which modules are active and installed but currently not in running state. The site is hardcoded as it must be part of the running list of modules, if not then it is added to the list of not running modules irrespective if it is activated or not.
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.
-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.
-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.
-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)
-spec env_backup_modules() -> [atom()].
List of modules enabled for backup sites.
Return the list of all modules running.
-spec get_modules_status(Context) -> ModulesStatus when Context :: z:context(), ModulesStatus :: [{atom(), module_status()}].
Return the status of all enabled modules.
Return the list of all provided functionalities in running modules.
Return the list of all modules that are activated but not present on the file system.
Return the status of any ongoing upgrade
Return a list of all modules
Sync enabled modules with loaded modules
Handle down messages from modules.
Initiates the server.
Check if a service is provided by any module.
-spec lib_dir(atom()) -> {error, bad_name} | file:filename().
-spec mod_author(Module) -> Author when Module :: atom() | binary() | string(), Author :: binary() | undefined.
Get the author of a module.
-spec mod_config(Module) -> ConfigList when Module :: atom() | binary() | string(), ConfigList :: [map()].
Get the configurations of a module.
-spec mod_description(Module) -> Desc when Module :: atom() | binary() | string(), Desc :: binary() | undefined.
Get the description of a module.
-spec mod_info(Module) -> Info when Module :: atom() | binary() | string(), Info :: #{app := atom(), prio := integer(), version := binary() | undefined, schema := integer() | undefined, title := binary() | undefined, description := binary() | undefined, app_dir := file:filename_all() | undefined}.
Fetch information about a module or site.
-spec mod_schema(Module) -> SchemaVersion when Module :: atom() | binary() | string(), SchemaVersion :: integer() | undefined.
Get the schema version of a module.
-spec mod_title(Module) -> Title when Module :: atom() | binary() | string(), Title :: binary() | undefined.
Get the title of a module.
Check if the code of a module exists. The database can hold module references to non-existing modules.
-spec module_reloaded(Module :: atom(), #context{cowreq :: cowboy_req:req() | undefined, cowenv :: cowboy_middleware:env() | undefined, site :: atom(), controller_module :: atom() | undefined, client_id :: binary() | undefined, client_topic :: mqtt_sessions:topic() | undefined, routing_id :: binary() | undefined, acl :: term() | admin | undefined, acl_is_read_only :: boolean(), user_id :: integer() | authenticated | undefined, render_state :: undefined | z_render:render_state(), db :: {atom(), atom()} | undefined, dbc :: pid() | undefined, language :: [atom()], tz :: binary(), props :: map(), depcache :: pid() | atom(), dispatcher :: pid() | atom(), template_server :: pid() | atom(), scomp_server :: pid() | atom(), dropbox_server :: pid() | atom(), pivot_server :: pid() | atom(), module_indexer :: pid() | atom(), translation_table :: atom()}) -> ok.
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.
-spec restart(Module :: atom(), #context{cowreq :: cowboy_req:req() | undefined, cowenv :: cowboy_middleware:env() | undefined, site :: atom(), controller_module :: atom() | undefined, client_id :: binary() | undefined, client_topic :: mqtt_sessions:topic() | undefined, routing_id :: binary() | undefined, acl :: term() | admin | undefined, acl_is_read_only :: boolean(), user_id :: integer() | authenticated | undefined, render_state :: undefined | z_render:render_state(), db :: {atom(), atom()} | undefined, dbc :: pid() | undefined, language :: [atom()], tz :: binary(), props :: map(), depcache :: pid() | atom(), dispatcher :: pid() | atom(), template_server :: pid() | atom(), scomp_server :: pid() | atom(), dropbox_server :: pid() | atom(), pivot_server :: pid() | atom(), module_indexer :: pid() | atom(), translation_table :: atom()}) -> 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,
Return a table with per dependeny which modules depend on it.
Return a table with per provision which modules provide it.
-spec sidejob_finish_start(Site) -> ok when Site :: atom().
Run after a site has been started up. Notify to the site that all modules are ready and load the translations.
-spec start_link(Site) -> {ok, Pid} | ignore | {error, Error} when Site :: atom(), Pid :: pid(), Error :: term().
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.
-spec upgrade(z:context()) -> ok.
Reload the list of all modules, add processes if necessary.
-spec upgrade_await(z:context()) -> ok | {error, timeout}.
Wait till all modules are started, used when starting up a new or test site.
Return the pid of a running module