Question

Laravel App Platform Cron Job

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; done

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?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
January 5, 2021
Accepted 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
done
Elan Hasson
DigitalOcean Employee
DigitalOcean Employee badge
December 1, 2022

Hi,

We recently launched Scheduled Functions (it’s in beta currently) which accomplishes what you’re looking to do. Scheduled Functions are not yet supported via App Platform Function components, so you would need to create a stand-alone Cloud Function which calls the API of your App Platform Service. Alternatively, you can do whatever work you need to do inside the function as long as it is within the runtime length limits of Functions (15 min max).

https://docs.digitalocean.com/products/functions/how-to/schedule-functions/

Hope this helps,

Elan

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.