#!/usr/bin/env bash
set -e
role=${CONTAINER_ROLE:-app}
if [ "$role" = "app" ]; then
    exec php-fpm
elif [ "$role" = "queue" ]; then
    echo "Running the queue..."
#    php /var/www/html/artisan queue:work --verbose --sleep=5 --tries=10 --max-time=3600
    php /var/www/html/artisan queue:work --verbose --sleep=5 --tries=10
elif [ "$role" = "websockets" ]; then
    echo "Running the websockets..."
    php /var/www/html/artisan websockets:serve
elif [ "$role" = "scheduler" ]; then
    while [ true ]
    do
      php /var/www/html/artisan schedule:run --verbose --no-interaction &
      sleep 60
    done
else
    echo "Could not match the container role \"$role\""
    exit 1
fi
