-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
176 lines (156 loc) · 4.54 KB
/
run.sh
File metadata and controls
176 lines (156 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
#
# RSS-Lance runtime commands (daily use)
#
# Lightweight script for running the fetcher, server, and admin tasks.
# Activates the Python venv automatically. Does NOT handle building
# or first-time setup - use build.sh for that.
#
# Usage:
# ./run.sh fetch-once # Fetch articles once and exit
# ./run.sh fetch-daemon # Run fetcher continuously
# ./run.sh server # Start the HTTP server
# ./run.sh demo-data # Insert demo RSS feeds
# ./run.sh add-feed <url> # Add a single feed URL
# ./run.sh datafix strip-chrome # Fix existing article data
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_PATH="$SCRIPT_DIR/.venv"
BUILD_DIR="$SCRIPT_DIR/build"
DATA_DIR="$SCRIPT_DIR/data"
FETCHER_DIR="$SCRIPT_DIR/fetcher"
DEBUG_FLAG=""
PORT_FLAG=""
ensure_venv() {
if [ ! -f "$VENV_PATH/bin/python" ]; then
echo "Python venv not found at: $VENV_PATH"
echo "Run build.sh setup first."
exit 1
fi
if [ ! -f "$VENV_PATH/bin/activate" ]; then
echo "Venv exists but activate script missing at: $VENV_PATH"
echo "Delete .venv/ and re-run: rm -rf .venv && ./build.sh setup"
exit 1
fi
source "$VENV_PATH/bin/activate"
}
cmd_fetch_once() {
ensure_venv
echo "Fetching articles (one-shot) ..."
python "$FETCHER_DIR/main.py" --once
}
cmd_fetch_daemon() {
ensure_venv
echo "Starting feed fetcher daemon ..."
python "$FETCHER_DIR/main.py"
}
cmd_server() {
local exe="$BUILD_DIR/rss-lance-server"
if [ ! -f "$exe" ]; then
echo "Server not built. Run build.sh server first."
exit 1
fi
echo "Loading RSS-Lance server (please wait) ..."
local args=()
if [ -n "$DEBUG_FLAG" ]; then
args+=("--debug" "$DEBUG_FLAG")
echo "Debug: $DEBUG_FLAG"
fi
if [ -n "$PORT_FLAG" ]; then
args+=("--port" "$PORT_FLAG")
echo "Port override: $PORT_FLAG"
fi
exec "$exe" "${args[@]}"
}
cmd_demo_data() {
ensure_venv
echo "Inserting demo feeds ..."
python "$FETCHER_DIR/demo_feeds.py" --data "$DATA_DIR"
}
cmd_export_opml() {
if [ -z "${1:-}" ]; then
echo "Usage: ./run.sh export-opml <output.opml>"
echo " Use '-' to write to stdout"
exit 1
fi
ensure_venv
echo "Exporting OPML ..."
python "$SCRIPT_DIR/migrate/export_opml.py" "$@"
}
cmd_datafix() {
if [ -z "${1:-}" ]; then
ensure_venv
python "$FETCHER_DIR/datafix.py" list
return
fi
ensure_venv
local fix_name="$1"
shift
echo "Running datafix: $fix_name"
python "$FETCHER_DIR/datafix.py" "$fix_name" --data "$DATA_DIR" "$@"
}
cmd_add_feed() {
if [ -z "${1:-}" ]; then
echo "Usage: ./run.sh add-feed <url>"
exit 1
fi
ensure_venv
echo "Adding feed: $1"
python "$FETCHER_DIR/main.py" --add "$1"
}
cmd_benchmark() {
ensure_venv
echo "Running benchmark ..."
python "$SCRIPT_DIR/tests/benchmark.py" "$@"
}
cmd_help() {
cat <<EOF
RSS-Lance Runtime Commands
==========================
Usage: ./run.sh <command> [args]
Commands:
fetch-once Fetch all due feeds once and exit
fetch-daemon Run the fetcher continuously on a schedule
server Start the HTTP server (http://127.0.0.1:8080)
demo-data Insert demo RSS feeds for testing
add-feed <url> Add a single RSS/Atom feed URL
export-opml <file> Export all feeds to an OPML file (use '-' for stdout)
datafix <name> Run a data fix on existing articles (or 'datafix' to list)
benchmark Run insertion & read benchmarks (isolated temp DB)
help Show this help
Options:
--debug <categories> Enable debug logging (client,duckdb,batch,lance,all)
--port <number> Override server port from config.toml
Examples:
./run.sh --debug all server
./run.sh --port 9090 server
./run.sh --debug client,duckdb server
EOF
}
# Parse --debug flag before command dispatch
while [[ $# -gt 0 ]]; do
case "$1" in
--debug)
DEBUG_FLAG="${2:-}"
shift 2
;;
--port)
PORT_FLAG="${2:-}"
shift 2
;;
*)
break
;;
esac
done
case "${1:-help}" in
fetch-once) cmd_fetch_once ;;
fetch-daemon) cmd_fetch_daemon ;;
server) cmd_server ;;
demo-data) cmd_demo_data ;;
add-feed) cmd_add_feed "${2:-}" ;;
export-opml) shift; cmd_export_opml "$@" ;;
datafix) shift; cmd_datafix "$@" ;;
benchmark) shift; cmd_benchmark "$@" ;;
help|*) cmd_help ;;
esac