Home > Software design >  Does Laravel run services on a schedule by default?
Does Laravel run services on a schedule by default?

Time:09-14

I Googled, I searched here, I didn't find my answer. If this is a duplicate to anyone, I apologize.

I have setup a Laravel application with a few different services that consume external APIs, does some basic transformations, then stores to a MySQL database, local to the server. Then, I also have some services that take that new data, transforms the data further, and adds to even more tables.

There's nothing wrong with any of these services, they work as intended, and currently are connected to buttons, via web routes, on a basic UI for testing. The plan is to move these to scheduled tasks, but I've not done anything with automating tasks so far.

However, this is where the question comes in. Does Laravel automatically run services in an app/services directory, by default in production?

I ask because I've never seen my database grow overtime automatically, in local Dev. However, once deployed to a DigitalOcean droplet, I am now seeing MySQL tables, that are connected to those services, growing on their own without my interaction. Again, I've done nothing directly with scheduling anything.

I'd show code, but there's no issues functionally. Just buttons connected to routes, routes to controllers, controllers calling services (app/services) and methods within those services... Any help would be appreciated.

CodePudding user response:

Some problems really butter me and after I solved them, that's like a joke. For this problem, check app\Console\Kernel.php and the schedule function there.

But, I think you didn't change that file, And I think your issue comes from some packages. Just check the packages that you installed in this project.

CodePudding user response:

Nothing should be running automatically.

To run tasks use the scheduler: https://laravel.com/docs/9.x/scheduling

You’ll need to set up a CRON * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1 - this runs every minute and will process your tasks. It may be that your hosting has set the sat up for you which is why you’re seeing changes - some Laravel specific hosting can configure this automatically for you.

  • Related