# Greenathon - cron for DirectAdmin
#
# install.sh writes the first block for you. This file is the reference, and it
# holds the second block you need only if you move the queue to Redis.
#
# Two ways to install, both editing the same user crontab:
#
#   crontab -e
#
# or through DirectAdmin > Advanced Features > Cron Jobs. Use whichever, but
# confirm afterwards with:
#
#   crontab -l
#
# ---------------------------------------------------------------------------
# 1. Scheduler and queue (QUEUE_CONNECTION=database, the default)
# ---------------------------------------------------------------------------
# install.sh adds this automatically, between its own marker comments, and
# logs to storage/logs/cron.log instead of /dev/null so that a failure is
# visible rather than silent.
#
# One entry per minute does everything, because routes/console.php hangs the
# queue drain off the scheduler:
#
#   ReconcilePendingPayments   every 15 minutes
#   ExpireStaleRegistrations   hourly
#   greenathon:send-reminders  daily at 09:00 Asia/Kolkata
#   greenathon:anonymise-expired  daily at 03:30
#   queue:work                 every minute, up to 50s, then exits
#
# MAILTO="" stops cron emailing you the output. Keep the log redirect: if the
# queue silently stops, cron.log is the only evidence.
#
MAILTO=""
* * * * * cd /home/greenathonzapnode/greenathon && /usr/local/php83/bin/php artisan schedule:run >> /home/greenathonzapnode/greenathon/storage/logs/cron.log 2>&1

# ---------------------------------------------------------------------------
# 2. Only if you switch the queue to Redis
# ---------------------------------------------------------------------------
# routes/console.php guards the built-in drain with:
#
#   ->when(fn () => config('queue.default') === 'database')
#
# so the moment QUEUE_CONNECTION becomes redis, the line above stops sending
# email entirely and nothing warns you. Add a second line:
#
#   * * * * * cd /home/greenathonzapnode/greenathon && /usr/local/php83/bin/php artisan queue:work redis --queue=mail,default --stop-when-empty --max-time=45 --tries=1 --no-interaction >> /home/greenathonzapnode/greenathon/storage/logs/cron-queue.log 2>&1
#
# --queue=mail,default matches the app: SendMessage goes to the "mail" queue
# (app/Jobs/SendMessage.php:24), everything else to "default".
# --max-time must stay below 60 so the worker finishes before the next tick and
# the two do not overlap.
#
# ---------------------------------------------------------------------------
# Checking that cron actually runs
# ---------------------------------------------------------------------------
# Some shared hosts silently clamp cron to hourly. Check the log, not the
# crontab: a correct-looking entry that never fires is the failure mode.
#
#   sleep 70 && tail -20 /home/greenathonzapnode/greenathon/storage/logs/cron.log
#
# If the file never appears, ask the host whether minute-level cron is
# permitted on your account. Reminders and the nightly anonymisation pass will
# otherwise run at the wrong time or not at all.
#
# ---------------------------------------------------------------------------
# PHP binary path
# ---------------------------------------------------------------------------
# Use the same PHP the web server serves. DirectAdmin installs the PHP selector
# under /usr/local/php83, and the default `php` in PATH is often an old base-OS
# build, so a cron entry using bare `php` can quietly run a different version
# than the site. Confirm with:
#
#   /usr/local/php83/bin/php -v
#
# Both install.sh and update.sh resolve the highest 8.2+ under /usr/local and
# write that absolute path into the crontab for you.
