falood/file_system

File watching seems to stop detecting file change events (created or renamed) after a while.

puruzio opened this issue · 0 comments

Using file_system 0.2.10 on Windows Server 2012 R2. Elixir 1.12.0-rc.1. Erland/OTP 21.

File_System has been working fine, but it started having issues recently since I upgraded Elixir and many other dependencies(including file_system) a week or so ago.

After my elixir app starts, file_system successfully detects file changes to the specified folder, but after a while it seems to stop detecting new changes. Is there a way to debug this issue? In :observer, FileSystem.Worker still shows up in the Processes tab, when it stops detecting.

In case it helps, here is my code.


defmodule FinReporting.Monitor do

  use GenServer
  alias FinReporting.Repo
  alias FinReporting.AppState

  def start_link(args) do
    GenServer.start_link(__MODULE__, args)
  end

  def init(args) do
    {:ok, watcher_pid} = FileSystem.start_link(args)

    FileSystem.subscribe(watcher_pid)
    IO.inspect(watcher_pid, label: "Watcher PID")
    {:ok, %{watcher_pid: watcher_pid}}
  end

  def handle_info(
        {:file_event, watcher_pid, {path, events}},
        %{watcher_pid: watcher_pid} = state
      ) do
    # Logic for path and events

    callback(path, events)
    {:noreply, state}
  end

  def handle_info(
        {:file_event, watcher_pid, :stop},
        %{watcher_pid: watcher_pid} = state
      ) do

    callback(:stop)
    {:noreply, state}
  end

  def callback(:stop) do
    IO.puts("STOP")
  end

  def callback(file_path, events) do
   ...