#!/bin/bash
#
# Laravel scheduler dispatcher — needed by anything declared in
# routes/console.php with the `Schedule::` facade.
#
# Today the only scheduled task is `billing:generate-invoices` which fires
# at 02:00 on the 1st of each month. Without this cron, monthly invoices
# never get generated.
#
# Trigger from cPanel Cron Jobs every minute (`* * * * *`). Laravel's
# scheduler is a no-op when nothing is due, so this is cheap.
#

set -e

PROJECT_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
PHP_BIN="${PHP_BIN:-php}"
LOG_DIR="${LOG_DIR:-$PROJECT_ROOT/storage/logs}"
mkdir -p "$LOG_DIR"

cd "$PROJECT_ROOT"

exec "$PHP_BIN" artisan schedule:run \
    >> "$LOG_DIR/cron-schedule.log" 2>&1
