tail v1.1.1 Tail View Source

Tail implements a simple file tail functionality.

Given a file, a function, and an interval, Tail will execute the function with a list of new lines found in the file and continue checking for additional lines on the interval.

Usage

{:ok, pid} = Tail.start_link("test.txt", &IO.inspect(&1), 1000) Tail.stop(pid)

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Handles :kill call. Checks for any final lines before stopping the genserver

Main loop. Calls check_for_lines, sleeps, then continues the loop by casting :check to self and returning with the (possibly updated) last_modified and position

Init callback. Starts the check loop by casting :check to self and then returns the initial state

Public interface. Starts a Tail Genserver for the given file, function, and interval (in ms)

Public interface. Sends a call to kill the GenServer

Link to this section Types

Link to this type

state()

View Source
state() ::
  {File.Stream.t(), ([String.t()] -> nil), integer(), term(), integer(),
   integer()}

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

handle_call(msg, from, state)

View Source
handle_call(:kill, {pid(), term()}, state()) :: {:stop, :normal, :ok, state()}

Handles :kill call. Checks for any final lines before stopping the genserver

Link to this function

handle_cast(msg, state)

View Source
handle_cast(:check, state()) :: {:noreply, state()}

Main loop. Calls check_for_lines, sleeps, then continues the loop by casting :check to self and returning with the (possibly updated) last_modified and position

Link to this function

init(arg)

View Source
init({String.t(), ([String.t()] -> nil), integer()}) :: {:ok, state()}

Init callback. Starts the check loop by casting :check to self and then returns the initial state

Link to this function

start_link(file, fun, interval \\ 1000)

View Source
start_link(String.t(), ([String.t()] -> nil), integer()) :: GenServer.on_start()

Public interface. Starts a Tail Genserver for the given file, function, and interval (in ms)

Public interface. Sends a call to kill the GenServer