Skip to content

Commit

Permalink
extract urls in async task
Browse files Browse the repository at this point in the history
  • Loading branch information
electronicbites committed Sep 1, 2024
1 parent c59128e commit 41ddc18
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions lib/radiator/outline/node_change_listener.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ defmodule Radiator.Outline.NodeChangeListener do
It is an eventconsumer that listens to changes in the outline and starts workers
"""
use GenServer

alias Radiator.Outline.Event.{
NodeContentChangedEvent,
NodeDeletedEvent,
NodeInsertedEvent,
NodeMovedEvent
}

alias Radiator.Outline.Dispatch
alias Radiator.UrlExtractor

def start_link(_) do
GenServer.start_link(__MODULE__, :ok, [])
Expand All @@ -15,19 +24,37 @@ defmodule Radiator.Outline.NodeChangeListener do
{:ok, []}
end

def handle_info(%Radiator.Outline.Event.NodeContentChangedEvent{} = _event, state) do
def handle_info(%NodeContentChangedEvent{node_id: node_id, content: content}, state) do
Task.async(fn ->
scan_content_for_urls(node_id, content)
end)

{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeInsertedEvent{} = _event, state) do
def handle_info(%NodeInsertedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeMovedEvent{} = _event, state) do
def handle_info(%NodeMovedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(%Radiator.Outline.Event.NodeDeletedEvent{} = _event, state) do
def handle_info(%NodeDeletedEvent{} = _event, state) do
{:noreply, state}
end

def handle_info(_reference, state) do
IO.inspect("Unknown event type")

Check warning on line 48 in lib/radiator/outline/node_change_listener.ex

View workflow job for this annotation

GitHub Actions / Build & Test

There should be no calls to `IO.inspect/1`.
{:noreply, state}
end

def scan_content_for_urls(_node_id, content) do
result = UrlExtractor.extract_urls(content)
IO.puts("Extracted #{Enum.count(result)} Urls!!")

Enum.each(result, fn info ->
IO.puts("URL: #{info.url}")
end)
end
end

0 comments on commit 41ddc18

Please sign in to comment.