blogit v1.2.3 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

Returns a specification to start this module under a supervisor.

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.

Callback implementation for GenServer.init/1.

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

Returns a specification to start this module under a supervisor.

See Supervisor.

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

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.