aboutsummaryrefslogtreecommitdiffstats
path: root/teaqueue-server
diff options
context:
space:
mode:
authorVG <vg@devys.org>2016-04-25 17:37:08 +0200
committerVG <vg@devys.org>2016-04-25 17:37:08 +0200
commitaf7b3997ed0b437348f3d1d0cb76d7e091a4cbed (patch)
tree448771de191e377cc99991cdc422d75d28baf644 /teaqueue-server
parented613df3074cfeae80397cb61d142fe159b18e8c (diff)
downloadteaqueue-af7b3997ed0b437348f3d1d0cb76d7e091a4cbed.tar.gz
teaqueue-af7b3997ed0b437348f3d1d0cb76d7e091a4cbed.tar.bz2
teaqueue-af7b3997ed0b437348f3d1d0cb76d7e091a4cbed.zip
Implement the teaqueue project.
- readme has been completed. - teaqueue-server has been implemented. - teaqueue-client has been implemented. - some worker examples have been written.
Diffstat (limited to 'teaqueue-server')
-rwxr-xr-xteaqueue-server53
1 files changed, 53 insertions, 0 deletions
diff --git a/teaqueue-server b/teaqueue-server
new file mode 100755
index 0000000..02c8b6a
--- /dev/null
+++ b/teaqueue-server
@@ -0,0 +1,53 @@
+#!/bin/bash
+# use bash for trap
+
+set -eu
+
+# default options
+queuefn="queue.txt"
+donefn="done.txt"
+port=1340
+
+usage()
+{
+ cat <<EOF
+Usage: $0 [OPTIONS...]
+
+Feeds lines from a text file to teaqueue-clients.
+
+Options:
+ -h, --help show usage
+ -p, --port what port to use (default: 1340)
+ -q, --queue what filename to use as input queue
+ -d, --done what filename to use for storing done items
+EOF
+}
+
+# arg parsing
+TEMP=$(getopt -o hH:p: --long help,host,port -n teaqueue-client -- "$@")
+if [ $? != 0 ]; then echo "Terminating..." >&2; exit 1; fi
+eval set -- "$TEMP"
+while true; do
+ case "$1" in
+ -h|--help) usage; exit 0;;
+ -p|--port) port="$2"; shift 2;;
+ -q|--queue) queuefn="$2"; shift 2;;
+ -d|--done) donefn="$2"; shift 2;;
+ --) shift; break;;
+ *) echo "Arguments parsing error" >&2; exit 1;;
+ esac
+done
+
+my_exit()
+{
+ mv "${queuefn}" "${queuefn}.old"
+ comm --nocheck-order -23 "${queuefn}.old" "${donefn}" > "${queuefn}"
+ exit 0
+}
+
+trap my_exit SIGINT SIGTERM
+
+cat "${queuefn}" | while read -r line; do
+ printf "%s\n" "$line" | nc -q0 -l -p $port
+ printf "%s\n" "$line"
+done > "${donefn}"