Skip to content

Instantly share code, notes, and snippets.

@Jesterovskiy
Last active November 29, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jesterovskiy/d238f796a6b6d12aa6e57f8bbcc2ca99 to your computer and use it in GitHub Desktop.
Save Jesterovskiy/d238f796a6b6d12aa6e57f8bbcc2ca99 to your computer and use it in GitHub Desktop.
Это код в GenServer который запускается каждые 5 минут
def handle_info(:work, state) do
IO.puts "Handle info"
body = HTTPoison.get!("long url").body
{:ok, pid} = GenServer.start_link(VideoProcessor.Process, [])
Enum.each(Floki.find(body, "item") |> Enum.slice(1, 2),
# Floki.find(body, "item"),
fn(x) ->
url = parse_xml(x, "link")
filename = parse_xml(x, "guid") <> ".mp4"
GenServer.call(pid, [url, filename])
end
)
schedule_work() # Reschedule once more
{:noreply, state}
end
Это код во втором GenSErver
def handle_call(request, _from, state) do
IO.puts "Get video"
IO.puts state.current_count
IO.puts state.queue
new_state =
if state.limit >= state.current_count do
Task.async(VideoProcessor.Process, :download, request)
%State{current_count: state.current_count + 1}
else
%State{queue: request}
end
{:noreply, new_state}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment