/lnsrv

Line-server, an HTTP server for synchronous distribution of text lines.

Primary LanguageGoMIT LicenseMIT

lnsrv

Command lnsrv (line server) is an HTTP server that serves input lines. The lines can be used to distribute labor to worker jobs using simple HTTP requests.

Each request to / returns the next line in a synchronous manner. When the input lines run out, a customizable end-string is emitted. The server can be configured to shut down after N end-strings.

Running lnsrv

Command line flags:

-end string
    String to send when no more lines are available. (default "END")
-f string
    File to read from. (default stdin)
-n uint
    Number of ENDs to send before exiting. (default infinite)
-port uint
    Port to listen on. (default 7777)

Querying lnsrv

Python

def get_lnsrv(addr:str, end='END') -> Iterable[str]:
    """Returns lines generated by Line Server (lnsrv) as an iterable."""
    line = requests.get(addr).text.strip()
    while line != end:
        yield line
        line = requests.get(addr).text.strip()

Bash

addr="..."
line="$(curl $addr)"
while [ "$line" != "END" ]; do
    echo "$line"
    line="$(curl $addr)"
done