board homeostasis

master
cynic 3 years ago
parent 2eed37b2a5
commit 0e75cf0faa
  1. 2
      lib/tir_inna_noc/imageboard.ex
  2. 13
      lib/tir_inna_noc/meldh.ex
  3. 2
      lib/tir_inna_noc/perenelle.ex

@ -9,7 +9,7 @@ defmodule TirInnaNoc.Imageboard do
if GenServer.call(:ratelimiter, :activate) == :goahead do if GenServer.call(:ratelimiter, :activate) == :goahead do
get(uri) get(uri)
else else
Process.sleep(1000) Process.sleep(1_000)
wget(uri) wget(uri)
end end
end end

@ -13,10 +13,12 @@ defmodule TirInnaNoc.Meldh do
@impl true @impl true
def handle_info(:update, state) do def handle_info(:update, state) do
IO.puts("upd8ing "<>state.board)
{:ok, res} = TirInnaNoc.Imageboard.threads(state.board) {:ok, res} = TirInnaNoc.Imageboard.threads(state.board)
res.body res.body
|> Enum.each(fn page -> |> Enum.each(fn page ->
Enum.each(page["threads"], fn thread -> Enum.each(page["threads"], fn thread ->
if state.threads[thread["no"]] == nil do
DynamicSupervisor.start_child( DynamicSupervisor.start_child(
String.to_atom(state.board<>"Supervisor"), String.to_atom(state.board<>"Supervisor"),
{ {
@ -30,15 +32,24 @@ defmodule TirInnaNoc.Meldh do
} }
} }
) )
else
send(String.to_atom(state.board<>to_string(thread["no"])<>"Perenelle"), {:update, page["page"], thread["replies"], false})
end
end) end)
end) end)
{:noreply, state} {:noreply, state}
end end
def go_forever(proc) do
send(proc, :update)
Process.sleep(60_000)
go_forever(proc)
end
@impl true @impl true
def init(state) do def init(state) do
IO.puts("started meldh to archive board "<>state.board) IO.puts("started meldh to archive board "<>state.board)
send(self(), :update) Task.start_link(fn -> go_forever(String.to_atom(state.board<>"Meldh")) end)
{:ok, state} {:ok, state}
end end
end end

@ -37,6 +37,8 @@ defmodule TirInnaNoc.Perenelle do
send(self(), {:addpost, post, sage_status}) send(self(), {:addpost, post, sage_status})
end) end)
end end
else
IO.puts("NOT UPDATING CUZ THERES NO UPDATE!!")
end end
state = %TirInnaNoc.Imageboard.Thread{state | on_page: new_page, reply_number: new_replynum} state = %TirInnaNoc.Imageboard.Thread{state | on_page: new_page, reply_number: new_replynum}
send(self(), :save) send(self(), :save)

Loading…
Cancel
Save