Laravel App Platform Cron Job

Posted January 5, 2021 1.6k views
LaravelDigitalOcean App Platform

Hello, i’ve been trying to run a cron job with a worker component.

This is my code:

while true; do
echo “=> Running scheduler”
cd core && php artisan booking:sync || true;
echo “=> Sleeping for 300 seconds”
sleep 300;

My artisan is inside a folder called core, the first time it works, but the second time i get an error of course because it’s already inside core folder. Is there a way to execute the cd core only once?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

👋🏼 @SteveEGL

Yes, that’s the right solution. You can move the cd core out of the while loop so that it’s only run once:

cd core

while true; do
  echo "=> Running scheduler"
  php artisan booking:sync || true
  echo "=> Sleeping for 300 seconds"
  sleep 300
  • I see, why didn’t i think of that.

    I used

    cd core || php artisan booking:sync || true

    Which made it work, but your solution is much more logical. Thank you.