Setting up Laravel Scheduler on Digital Ocean

Solved
graham

Sep 14th, 2023 11:42 PM

Hello, I'm looking to set up some cron jobs to process emails, and other things that don't need to happen in realtime with my users' session.

How do you go about doing this with Digital Ocean App Platform? I don't see any place to kick off the php artisan schedule:run command

Cheers, Graham.

bobbyiliev

Sep 18th, 2023 05:41 AM

Best Answer

Hey Graham,

Yes indeed, there isn't a direct way to do that but there are a couple of work around ways of doing this:

You can use an HTTP endpoint and this cron service here:

  • First setup a route to expose the schedule command in your Laravel app, eg:
use Illuminate\Support\Facades\Artisan;

Route::get('/cron', function() {
    Artisan::call('schedule:run');
    return 'Scheduled tasks executed!';
});
  • Then setup a corn service as described here to trigger that route using a curl command:

How To Setup a Job Scheduler on DigitalOcean App Platform

You would just need to update the curl command from the above documentation to correspond to the schedule route that you've added.

Let me know if this works for you!

Best,

Bobby

graham

Sep 18th, 2023 10:00 PM

Thanks Bobby! this is a pretty interesting approach.

I guess if I went the URL based approach, and didn't need to consistently have the every minute check, I could use a health check monitor to hit a specific URL that triggers the schedule artisan command, instead of booting up another digital oceans app. It wouldn't work for time sensitive stuff, but could be used to process things asynchronously.

Thanks for the response! I appreciate the help 🙂

bobbyiliev

Sep 19th, 2023 07:56 AM

Hey! No problem at all! Happy to help and good luck with your project!