This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule SomeApp.Migration do | |
| defmacro __using__(_) do | |
| quote do | |
| import Ecto.Migration, except: [timestamps: 0, timestamps: 1] | |
| @disable_ddl_transaction false | |
| import unquote(__MODULE__) | |
| @before_compile Ecto.Migration | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # how to boot a new VM process | |
| def spawn do | |
| :net_kernel.start([:"primary@127.0.0.1"]) | |
| :erl_boot_server.start([]) | |
| allow_boot to_char_list("127.0.0.1") | |
| Application.get_env(:highlander, | |
| :spawn_nodes, []) | |
| |> Enum.map(&Task.async(fn -> | |
| {:ok, _node} = spawn_node(&1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule User do | |
| use Highlander.Object, type: :user | |
| defobject name: "", email: "", known_lists: [] | |
| end | |
| defmodule List do | |
| use Highlander.Object, type: :list | |
| defobject title: "", todos: [], allowed_users: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule List do | |
| use Highlander.Object, type: :list | |
| defobject title: "", todos: [] | |
| end | |
| defmodule Todo do | |
| defstruct title: "", completed: false, color: :blue | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule User do | |
| use Highlander.Object, type: :user | |
| defobject name: "", email: "" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| id = UUID.uuid4() | |
| {:ok, todo} = Todo.get id | |
| assert todo.completed == false | |
| assert todo.title == "" | |
| assert todo.color == :blue | |
| todo = %{todo | title: "Hello"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Todo do | |
| use Highlander.Object, type: :todo | |
| defobject title: "", completed: false, color: :blue | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| opts = [host, | |
| [stop_on_disconnect: true, name: :zk]] | |
| children = [ | |
| worker(Zookeeper.Client, opts, []), | |
| worker(Registry.Server, [], []), | |
| worker(Registry.NodeCycleServer, [], []), | |
| supervisor(Object.Supervisor, [], []) | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule ZNode do | |
| def init(name) do | |
| {:ok, path} = | |
| Zookeeper.Client.create(:zk, | |
| prefix(name, UUID.uuid4(:hex)), | |
| to_string(Node.self), | |
| makepath: true, | |
| create_mode: :ephemeral_sequential) | |
| {:ok, %{path: path, name: name}} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule ZK do | |
| def create_znode(name) do | |
| {:ok, pid} = ZNode.start_link(name) | |
| if ZNode.first?(pid) do | |
| {:ok, pid} | |
| else | |
| :ok = ZNode.delete(pid) | |
| {:error, :already_exists} | |
| end |