Verbatim port of Fastway-Server's TFWScheduler from fw_scheduler.pas
per feedback_copy_dont_reinterpret.md. Library named fpc-cron;
class TCron. Adjustments limited to:
- Type renames per family convention.
- uses clause: drop fw_consts/fw_log/fw_config/fw_database/
fw_plugin_*/dbapi_*; add log.types (fpc-log) + db.dialect/
schema/pool (fpc-db v0.3.0) + cron.types + cron.events.
fpc-cron does NOT depend on fpc-events.
- TDBPool injected on Create where canonical used global DB.
- Logging through optional log.types.TLogProc callback (the
canonical ecosystem-wide logger shape used by every other
fpc-* library). Category='cron'.
- Events: typed observer callbacks (cron.events) instead of
canonical's EventBus.Fire calls. OnTaskStart /
OnTaskComplete / OnTaskRegistered / OnPluginOrphaned /
OnThreadStart / OnThreadStop are assignable properties on
TCron. Same per-library typed-callback pattern as
fpc-binkp's bp.events and fpc-comet's cm.events.
- System-task dispatch: consumer-registered via
RegisterSystemTask (no Fastway-specific log_cleanup / etc.
baked in). Dispatcher shape preserved.
- DoWalCheckpointTruncate lifted out (Fastway-specific).
- No global Scheduler singleton.
- ParseCronField / MatchesCron promoted to class function for
test access; bodies byte-verbatim from canonical (verified
by normalised diff).
Schema: system_scheduler + scheduler_log table names + columns
preserved verbatim from canonical fw_schema.pas, so an existing
Fastway database is reusable as-is.
Behaviours preserved verbatim: cron grammar (5-field, *, */N,
a,b,c, a-b, a-b/N, literal), UTC math via LocalTimeToUniversal,
schedule-miss-on-long-task semantics, TThread + PRTLEvent +
1-second wake loop, suspended-Create + .Start, SyncPluginTasks
orphan cleanup, MatchesCron's DecodeDateFully call (cosmetic but
present in canonical), MatchesCron's pre-try-finally TBits
allocation (known leak inherited verbatim and documented).
Docs: README + docs/API.md + docs/architecture.md +
docs/DEVELOPER_GUIDE.md. fpc.cfg for multi-target builds.
Tests: 73 assertions across 23 scenarios (37 pure-cron + 36
SQLite-backed end-to-end) pass on x86_64-linux. Pre-tag -vh
audit on src/ reports zero hints/warnings on cron.* units.
76 lines
1.6 KiB
Bash
Executable File
76 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# run_tests.sh -- compile and run every test in tests/, then
|
|
# compile every example in examples/.
|
|
|
|
set -e
|
|
cd "$(dirname "$0")"
|
|
FPC=/opt/fpcup/fpc/bin/x86_64-linux/fpc
|
|
OUT=build
|
|
mkdir -p "$OUT"
|
|
|
|
bash build.sh > /dev/null
|
|
|
|
SEARCH=(
|
|
"-Fusrc"
|
|
"-Fu../fpc-log/src"
|
|
"-Fu../fpc-db/src"
|
|
)
|
|
|
|
TESTS=$(find tests -maxdepth 1 -name 'test_*.pas' 2>/dev/null | sort)
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
for f in $TESTS; do
|
|
name=$(basename "$f" .pas)
|
|
printf " %-32s " "$name"
|
|
if $FPC -O2 -Sh -B \
|
|
"${SEARCH[@]}" \
|
|
-FE"$OUT" \
|
|
-FU"$OUT" \
|
|
-o"$OUT/$name" \
|
|
"$f" > "$OUT/$name.compile.log" 2>&1; then
|
|
if "$OUT/$name" > "$OUT/$name.run.log" 2>&1; then
|
|
echo "PASS"
|
|
PASS=$((PASS+1))
|
|
else
|
|
echo "FAIL (runtime)"
|
|
sed 's/^/ /' < "$OUT/$name.run.log"
|
|
FAIL=$((FAIL+1))
|
|
fi
|
|
else
|
|
echo "FAIL (compile)"
|
|
cat "$OUT/$name.compile.log"
|
|
FAIL=$((FAIL+1))
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "Tests: $PASS passed, $FAIL failed."
|
|
|
|
EX_PASS=0
|
|
EX_FAIL=0
|
|
echo
|
|
echo "Examples (compile-only):"
|
|
for f in examples/*.pas; do
|
|
[ -e "$f" ] || continue
|
|
name=$(basename "$f" .pas)
|
|
printf " %-32s " "$name"
|
|
if $FPC -O2 -Sh -B \
|
|
"${SEARCH[@]}" \
|
|
-FE"$OUT" \
|
|
-FU"$OUT" \
|
|
-o"$OUT/$name" \
|
|
"$f" > "$OUT/$name.compile.log" 2>&1; then
|
|
echo "OK"
|
|
EX_PASS=$((EX_PASS+1))
|
|
else
|
|
echo "FAIL (compile)"
|
|
cat "$OUT/$name.compile.log"
|
|
EX_FAIL=$((EX_FAIL+1))
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "Examples: $EX_PASS built, $EX_FAIL failed."
|
|
[ $FAIL -eq 0 ] && [ $EX_FAIL -eq 0 ]
|