Is there a way to launch a cron job in the app platform?

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.

×
2 answers

👋 @john375105

A cron jobs feature is on our roadmap, though I don’t have a public release date as of right now. In the meantime, one option is to run a Worker component that acts as a cron job.

If you needed something the runs continuously you could use a worker with a run command like:

while true; do
    echo "=> Running scheduler"
    php artisan schedule:run || true;
    echo "=> Sleeping for 60 seconds"
    sleep 60;
done
  • @jfriesen

    How this code is supose to be in a github repository as valid for App detection?

    • 👋 @matheusstag

      This code is an example of a triggering Laravel tests. It would be used alongside a Laravel app in a worker component.

      • Thanks for reply.

        I didn’t express myself well, but I found the way.
        Just setup same repository as worker component and change the run command from
        heroku-php-apache2 public/
        to

        while true; do
            echo "=> Running scheduler"
            php artisan schedule:run || true;
            echo "=> Sleeping for 60 seconds"
            sleep 60;
        done
        

        Now I’m wondering what it would be like run php artisan queue:work as the same way. For now, my tests doesn’t work

It’s not working.

I added the code but my deployment keeps failing after I added this worker

Submit an Answer