Skip to content

Instantly share code, notes, and snippets.

View x-ji's full-sized avatar

Xiang Ji x-ji

View GitHub Profile
@x-ji
x-ji / Markdium-elixir.ex
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
### In mix.exs
defp deps do
[
...
{:libcluster, "~> 3.1"},
...
]
end
### In config/prod.exs
@x-ji
x-ji / Markdium-elixir.ex
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
defmodule Yourapp.YourSupervisor do
use DynamicSupervisor
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
def start_link(state) do
DynamicSupervisor.start_link(__MODULE__, state, name: __MODULE__)
end
def init(_) do
@x-ji
x-ji / Markdium-elixir.ex
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
Swarm.register_name(
:unique_name_for_this_worker,
Yourapp.YourSupervisor,
:register,
[Yourapp.YourWorker]
)
@x-ji
x-ji / Markdium-Shell.sh
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
# In Dockerfile:
ENTRYPOINT ["/opt/app/docker-entrypoint-dev.sh"]
# In docker-entrypoint-dev.sh:
if [ -z ${NODE_IP+x} ]; then
export NODE_IP="$(hostname -i | cut -f1 -d' ')"
fi
elixir --name yourapp@${NODE_IP} --cookie "your_dev_erlang_cookie" -S mix phx.server
@x-ji
x-ji / Markdium-elixir.ex
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
# Change the handling of :begin_handoff
# This is triggered whenever a registered process is to be killed.
def handle_call({:swarm, :begin_handoff}, _from, current_state) do
{:reply, {:resume, produce_outgoing_state(current_state)}, current_state}
end
# Handle :end_handoff
# This is triggered whenever a process has been restarted on a new node.
def handle_call({:swarm, :end_handoff, incoming_state}, _from, current_state) do
{:noreply, end_handoff_new_state(current_state, incoming_state)}
@x-ji
x-ji / Markdium-YAML.yaml
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
services:
your_app: &app
build:
context: ./app
ports:
- 4000:4000
# ...
your_app_2:
<<: *app
@x-ji
x-ji / Markdium-elixir.ex
Created December 12, 2019 19:14
Markdium-Elixir process orchestration in Kubernetes with libcluster and swarm
defmodule Yourapp.YourWorker do
use GenServer
def start_link(state) do
GenServer.start_link(__MODULE__, state)
end
def init(opts) do
initial_state = initialize_worker(opts)
@x-ji
x-ji / Markdium-text.txt
Created October 18, 2019 14:48
Markdium-Language Server Protocol
(lsp :variables
lsp-ui-doc-enable nil)
@x-ji
x-ji / Markdium-text.txt
Created October 18, 2019 14:48
Markdium-Language Server Protocol
# In `dotspacemacs/layers`:
(elixir :variables
elixir-backend 'lsp
elixir-ls-path "path-to-elixir-ls/release-1.9.0"
@x-ji
x-ji / Markdium-text.txt
Created October 18, 2019 14:48
Markdium-Language Server Protocol
# In dotspacemacs/user-config
(add-hook 'vue-mode-hook
(lambda ()
(add-hook 'before-save-hook #'prettier-js nil t)))