blogit v1.2.1 Blogit.Server View Source

This module represents the core process of Blogit.

The process is responsible for loading the blog data from a repository, using specified Blogit.RepositoryProvider implementation and keeping it converted into structures. The component processes use these structures as their state.

If polling is configured to true, this process polls for changes in the source repository on interval, configured with poll_interval. By default this interval is 10 seconds.

This process is started and supervised as worker by Blogit.Supervisor. It uses Task processes to check for updated, which are supervised by the Task.Supervisor process, started and supervised by Blogit.Supervisor.

If there are changes in the source repository, it is this process’ responsibility to update the component processes.

The component processes are added as workers by this process to the Blogit.Components.Supervisor, which starts with no workers. This is so, because they are dependent on the Blogit.Server process and it must be started and ready to accept messages before them.

Link to this section Summary

Functions

Retrives part of the state of the Blogit.Server process - the Blogit.Models.Configuration struct it holds for the given language

Retrives part of the state of the Blogit.Server process - the list of Blogit.Models.Post structs it holds for the given language

Invoked when the server is started. start_link/3 or start/3 will block until it returns

Link to this section Types

Link to this type t() View Source
t() :: %Blogit.Server{configurations: [Blogit.Models.Configuration.t], posts: %{optional(atom) => Blogit.Models.Post.t}, repository: Blogit.RepositoryProvider.t}

Link to this section Functions

Link to this function get_configuration(language) View Source
get_configuration(String.t) :: Blogit.Models.Configuration.t

Retrives part of the state of the Blogit.Server process - the Blogit.Models.Configuration struct it holds for the given language.

Sends a call to the {:get_configuration, language} call handler of the process.

Retrives part of the state of the Blogit.Server process - the list of Blogit.Models.Post structs it holds for the given language.

Sends a call to the {:get_posts, language} call handler of the process.

Link to this function init(repository_provider) View Source

Invoked when the server is started. start_link/3 or start/3 will block until it returns.

args is the argument term (second argument) passed to start_link/3.

Returning {:ok, state} will cause start_link/3 to return {:ok, pid} and the process to enter its loop.

Returning {:ok, state, timeout} is similar to {:ok, state} except handle_info(:timeout, state) will be called after timeout milliseconds if no messages are received within the timeout.

Returning {:ok, state, :hibernate} is similar to {:ok, state} except the process is hibernated before entering the loop. See c:handle_call/3 for more information on hibernation.

Returning :ignore will cause start_link/3 to return :ignore and the process will exit normally without entering the loop or calling c:terminate/2. If used when part of a supervision tree the parent supervisor will not fail to start nor immediately try to restart the GenServer. The remainder of the supervision tree will be (re)started and so the GenServer should not be required by other processes. It can be started later with Supervisor.restart_child/2 as the child specification is saved in the parent supervisor. The main use cases for this are:

  • The GenServer is disabled by configuration but might be enabled later.
  • An error occurred and it will be handled by a different mechanism than the Supervisor. Likely this approach involves calling Supervisor.restart_child/2 after a delay to attempt a restart.

Returning {:stop, reason} will cause start_link/3 to return {:error, reason} and the process to exit with reason reason without entering the loop or calling c:terminate/2.

Callback implementation for GenServer.init/1.

Link to this function start_link(repository_provider) View Source
start_link(module) :: GenServer.on_start

Starts the Blogit.Server process.

This function has one argument - a module which must implement the Blogit.RepositoryProvider behaviour. It is used to read data from the source repository and to check for updates.

Once the process starts, it reads all the data from the repository, using the given provider, converts it to Blogit.Models structures and creates the component processes.

Every component process should retrieve the data it needs from the Blogit.Server process. When there are updates, the blogit server will update its components.