Powered by AppSignal & Oban Pro

Slink notes

notes/dev.livemd

Slink notes

Mix.install([
  {:kino, "~> 0.16.0"},
  {:kino_db, "~> 0.3.0"},
  {:postgrex, "~> 0.18"},
  {:kino_explorer, "~> 0.1.20"},
  {:merquery, "~> 0.3.0"}
])

Knonw bugs

  • Unspport non chrome-extension://xxxx like non-http links in code

Test accounts

ref test/support/fixtures.ex

  • a1@b.c / 123456123456

DB

opts = [
  hostname: "localhost",
  port: 5432,
  username: "postgres",
  password: "postgres",
  database: "slink_dev"
]

{:ok, conn} = Kino.start_child({Postgrex, opts})
Kino.nothing()
result = Postgrex.query!(conn, ~S"select * from users order by id asc", [])
result2 =
  Postgrex.query!(conn, ~S"select * from users_tokens order by id desc limit 30", [])

Node info

%{
  node: Node.self,
  cookie: Node.get_cookie(),
  nodes: Node.list
} |> Kino.Tree.new()

Local app links

Remote execution

in slink project run:

task node6
require Kino.RPC
node = :"slink@mac.local"
Node.set_cookie(node, :slink)
Kino.RPC.eval_string(node, ~S"Slink.Links.Link.first", file: __ENV__.file)

DB explore

opts = [
  hostname: "localhost",
  port: 5432,
  username: "postgres",
  password: "postgres",
  database: "slink_dev"
]

{:ok, local_conn} = Kino.start_child({Postgrex, opts})
local_links =
  Postgrex.query!(local_conn, ~S"select * from links order by id desc limit 5", [])

Flyio app links

API requests

req =
  Req.new(
    method: :get,
    url: "http://slink.internal:8080/api/ping",
    headers: %{},
    params: %{"http://slink.internal:8080/api/ping" => ""}
  )
req = Req.merge(req, inet6: true)
{req, flyio_resp} = Req.request(req)
flyio_resp.body|>Kino.Tree.new()

DB connection

使用fly 6PN地址,如 shareup-db.internal

  • 注意开启IPv6开关
opts = [
  hostname: "shareup-db-pg17.internal",
  port: 5432,
  username: "slink",
  password: System.fetch_env!("LB_FLY_SLINK_DB_PASSWORD"),
  database: "slink",
  socket_options: [:inet6]
]

{:ok, flyio_conn} = Kino.start_child({Postgrex, opts})
flyio_links =
  Postgrex.query!(
    flyio_conn,
    ~S"select * from links order by updated_at desc limit 3",
    []
  )

Remote execution

req =
  Req.new(
    method: :get,
    url: "http://slink.internal:8080/api/ping",
    headers: %{},
    params: %{"http://slink.internal:8080/api/ping" => ""}
  )
req = Req.merge(req, inet6: true)
{req, flyio_resp} = Req.request(req)
flyio_resp.body |> Kino.Tree.new
Below remote-execution require local livebook running in inet6 mode, like
  node6:
    env:
      LIVEBOOK_DISTRIBUTION: name
      # Note: should use inet6 when connect to Flyio app?
      LIVEBOOK_NODE: "lv@::1"
      LIVEBOOK_COOKIE: "livebook"
      ERL_AFLAGS: "-proto_dist inet6_tcp -kernel shell_history enabled"
    cmds:
      - |
        iex -S mix phx.server
require Kino.RPC
node = :"slink-01K2BZRVFZS0TZNRR7WH56WRZ6@fdaa:2:686c:a7b:17b:eab4:2a91:2"
Node.set_cookie(node, :"happy-cookie-not-secret-but-for-cluster")
ss = Kino.RPC.eval_string(node, ~S"Slink.Links.Link.last", file: __ENV__.file)