Skip to content

Commit

Permalink
add handle_continue login
Browse files Browse the repository at this point in the history
  • Loading branch information
nunsez committed Mar 4, 2023
1 parent 8101af2 commit d34ca82
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions lib/kaize_votes/worker2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,7 @@ defmodule KaizeVotes.Worker2 do

{:noreply, new_state}
else
Process.send_after(self(), :login, Timeout.before_login())

{:noreply, state}
end
end

def handle_info(:login, state) do
document = Document.fetch_document(Constants.proposal_index_url())

if Login.logged_in?(document) do
Process.send_after(self(), :enqueue, Timeout.before_next())

{:noreply, state}
else
location = Login.login()

case location do
{:ok, _} ->
Process.send_after(self(), :enqueue, Timeout.before_next())

{:noreply, state}
error ->
Logger.error("Login failed, stop")

{:stop, error}
end
{:noreply, state, {:continue, :login}}
end
end

Expand All @@ -92,7 +67,7 @@ defmodule KaizeVotes.Worker2 do

cond do
Login.logged_out?(document) ->
Process.send_after(self(), :login, Timeout.before_login())
{:noreply, state, {:continue, :login}}

Votable.can_vote_down?(document) ->
Process.sleep(Timeout.before_vote())
Expand Down Expand Up @@ -129,6 +104,32 @@ defmodule KaizeVotes.Worker2 do
{:noreply, state}
end

@impl GenServer
def handle_continue(:login, state) do
Process.sleep(Timeout.before_next())
document = Document.fetch_document(Constants.proposal_index_url())

if Login.logged_in?(document) do
Process.send_after(self(), :enqueue, Timeout.before_next())

{:noreply, state}
else
Process.sleep(Timeout.before_login())
location = Login.login()

case location do
{:ok, _} ->
Process.send_after(self(), :enqueue, Timeout.before_next())

{:noreply, state}
error ->
Logger.error("Login failed, stop")

{:stop, error}
end
end
end

@spec votable?(Proposal.t()) :: boolean()
defp votable?(proposal) do
if proposal.status == :unvoted do
Expand Down

0 comments on commit d34ca82

Please sign in to comment.