structs for board/thread state

master
cynic 3 years ago
parent de70439f3e
commit d352666d96
  1. 3
      lib/tir_inna_noc/imageboard/board.ex
  2. 2
      lib/tir_inna_noc/imageboard/thread.ex
  3. 21
      lib/tir_inna_noc/meldh.ex
  4. 2
      lib/tir_inna_noc/merlin.ex
  5. 5
      lib/tir_inna_noc/perenelle.ex
  6. 2
      lib/tir_inna_noc/rate.ex
  7. 4
      mix.lock

@ -0,0 +1,3 @@
defmodule TirInnaNoc.Imageboard.Board do
defstruct board: "", threads: %{}
end

@ -1,3 +1,3 @@
defmodule TirInnaNoc.Imageboard.Thread do
defstruct last_update: 0, on_page: 0, reply_number: 0, posts: ""
defstruct board: "", no: 0, last_update: 0, on_page: 0, reply_number: 0, posts: ""
end

@ -2,25 +2,34 @@ defmodule TirInnaNoc.Meldh do
use GenServer
def start_link(state) do
GenServer.start_link(__MODULE__, state, name: String.to_atom(elem(state, 0)<>"Meldh"))
GenServer.start_link(__MODULE__, state, name: String.to_atom(state.board<>"Meldh"))
end
@impl true
def handle_info({:checkin, no, pid}, state) do
state = {elem(state, 0), Map.put(elem(state, 1), no, pid)}
state = %TirInnaNoc.Imageboard.Board{board: state.board, threads: Map.put(state.threads, no, pid)}
{:noreply, state}
end
@impl true
def init(state) do
IO.puts("started meldh to archive board "<>elem(state, 0))
{:ok, res} = TirInnaNoc.Imageboard.threads(elem(state, 0))
IO.puts("started meldh to archive board "<>state.board)
{:ok, res} = TirInnaNoc.Imageboard.threads(state.board)
res.body
|> Enum.each(fn page ->
Enum.each(page["threads"], fn thread ->
DynamicSupervisor.start_child(
String.to_atom(elem(state, 0)<>"Supervisor"),
{TirInnaNoc.Perenelle, {elem(state, 0), thread["no"]}}
String.to_atom(state.board<>"Supervisor"),
{
TirInnaNoc.Perenelle,
%TirInnaNoc.Imageboard.Thread{
board: state.board,
no: thread["no"],
last_update: thread["last_modified"],
reply_number: thread["replies"],
on_page: page
}
}
)
end)
end)

@ -13,7 +13,7 @@ defmodule TirInnaNoc.Merlin do
DynamicSupervisor.start_child(
MerlinSupervisor, {DynamicSupervisor, strategy: :one_for_one, name: String.to_atom(board<>"Supervisor")}
)
DynamicSupervisor.start_child(MerlinSupervisor, {TirInnaNoc.Meldh, {board, %{}}})
DynamicSupervisor.start_child(MerlinSupervisor, {TirInnaNoc.Meldh, %TirInnaNoc.Imageboard.Board{board: board, threads: %{}}})
end)
{:ok, a}
end

@ -2,13 +2,14 @@ defmodule TirInnaNoc.Perenelle do
use GenServer
def start_link(state) do
GenServer.start_link(__MODULE__, state, name: String.to_atom(elem(state, 0)<>to_string(elem(state, 1))<>"Perenelle"))
GenServer.start_link(__MODULE__, state, name: String.to_atom(state.board<>to_string(state.no)<>"Perenelle"))
end
@impl true
def init(state) do
IO.puts("watching thread "<>inspect(state))
send(String.to_atom(elem(state, 0)<>"Meldh"), {:checkin, elem(state, 1), self()})
send(String.to_atom(state.board<>"Meldh"), {:checkin, state.no, self()})
TirInnaNoc.Imageboard.thread(state.board, state.no) |> inspect |> IO.puts
{:ok, state}
end
end

@ -13,7 +13,7 @@ defmodule TirInnaNoc.Rate do
@impl true
def handle_call(:activate, _, last_activity) do
if :os.system_time(:millisecond) - last_activity > 10_000 do
if :os.system_time(:millisecond) - last_activity > 1_000 do
last_activity = :os.system_time(:millisecond)
{:reply, :goahead, last_activity}
else

@ -1,8 +1,11 @@
%{
"castore": {:hex, :castore, "0.1.18", "deb5b9ab02400561b6f5708f3e7660fc35ca2d51bfc6a940d2f513f89c2975fc", [:mix], [], "hexpm", "61bbaf6452b782ef80b33cdb45701afbcf0a918a45ebe7e73f1130d661e66a06"},
"cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm", "1e1a3d176d52daebbecbbcdfd27c27726076567905c2a9d7398c54da9d225761"},
"finch": {:hex, :finch, "0.13.0", "c881e5460ec563bf02d4f4584079e62201db676ed4c0ef3e59189331c4eddf7b", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "49957dcde10dcdc042a123a507a9c5ec5a803f53646d451db2f7dea696fba6cc"},
"gun": {:hex, :gun, "1.3.3", "cf8b51beb36c22b9c8df1921e3f2bc4d2b1f68b49ad4fbc64e91875aa14e16b4", [:rebar3], [{:cowlib, "~> 2.7.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "3106ce167f9c9723f849e4fb54ea4a4d814e3996ae243a1c828b256e749041e0"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
"mint": {:hex, :mint, "1.4.2", "50330223429a6e1260b2ca5415f69b0ab086141bc76dc2fbf34d7c389a6675b2", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}], "hexpm", "ce75a5bbcc59b4d7d8d70f8b2fc284b1751ffb35c7b6a6302b5192f8ab4ddd80"},
@ -11,4 +14,5 @@
"redix": {:hex, :redix, "1.1.5", "6fc460d66a5c2287e83e6d73dddc8d527ff59cb4d4f298b41e03a4db8c3b2bd5", [:mix], [{:castore, "~> 0.1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "679afdd4c14502fe9c11387ff1cdcb33065a1cf511097da1eee407f17c7a418b"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
"tesla": {:hex, :tesla, "1.4.4", "bb89aa0c9745190930366f6a2ac612cdf2d0e4d7fff449861baa7875afd797b2", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.3", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "d5503a49f9dec1b287567ea8712d085947e247cb11b06bc54adb05bfde466457"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}

Loading…
Cancel
Save