Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.
/ agentex Public archive

Elixir distributed agent implementation on top of Mnesia

Notifications You must be signed in to change notification settings

am-kantox/agentex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Agentex

Elixir distributed agent implementation on top of Mnesia

Installation

In mix.exs:

def deps do
  [
    ...
    {:agentex, "~> 0.1"}
  ]
end

def application do
    [
      ...
      applications: [
        ...
        :agentex
      ]
end

Preparation

Schema

$ iex --cookie agentex -S mix run.distributed
  Erlang/OTP 19 [erts-8.3] [...]

Interactive Elixir (1.5.0-dev) - [...]
iex(primary@127.0.0.1)1> nodes = [Node.self | Node.list]                
iex(primary@127.0.0.1)2> Amnesia.stop
:stopped
iex(primary@127.0.0.1)3> :rpc.multicall(nodes, Amnesia, :stop, [])
{[:stopped, :stopped, :stopped, :stopped, :stopped], []}
iex(primary@127.0.0.1)4> Amnesia.Schema.destroy
:ok
iex(primary@127.0.0.1)5> Amnesia.Schema.create(nodes)
:ok

Usage

Agentex.put :pi, 3.14
Agentex.get :pi
#⇒ 3.14
Agentex.put :credentials, %{user: "john", pass: "*********"}
Agentex.get :credentials
#⇒ %{user: "john", pass: "*********"}

Distributed usage

config.exs

config :agentex, :nodes, ~w|n1@127.0.0.1 n2@127.0.0.1|a

Make sure, the Agentex application with the same config is starting on all the nodes listed. The first node would be considered “master” node. It will be used to produce schema and re-create tables on each subsequent application restart.

By default, the only database Agentex.Simple with the single table Agentex.Simple.Kv of type key ⇒ value is being created, though one might specify their own database, containing as many tables as needed.

In the latter case, to distinguish Agentex.{get,put} calls between different tables, the table module atom should be specified as the very first parameter:

Agentex.put Agentex.Db.Math, :pi, 3.14
Agentex.get Agentex.Db.Math, :pi
#⇒ 3.14

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/agentex.

About

Elixir distributed agent implementation on top of Mnesia

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages