#!/bin/sh
set -e

echo "Deploying uat application ..."
    # down laravel
    php artisan down
    # Update codebase
    git fetch origin uat_deploy
    git reset --hard origin/uat_deploy
    #composer install
    composer install
    # migrate db
    php artisan migrate --no-interaction
    # clear cache
    php artisan optimize:clear

    # Restart Queue Worker
    echo "Restarting queue worker..."
    if pgrep -f "artisan queue:work" > /dev/null; then
        echo "Stopping existing queue worker..."
        pkill -f "artisan queue:work"
    fi
    nohup php artisan queue:work --tries=3 --timeout=1800 --queue=default > storage/logs/queue.log 2>&1 &

    #up laravel
    php artisan up
echo "Application uat deployed!"