Last active
November 29, 2016 15:06
-
-
Save Jesterovskiy/d238f796a6b6d12aa6e57f8bbcc2ca99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Это код в 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