Skip to content

Instantly share code, notes, and snippets.

@timothycarambat
Last active October 16, 2020 18:22
Show Gist options
  • Save timothycarambat/340c2a14d3a0745cac33378d457ed104 to your computer and use it in GitHub Desktop.
Save timothycarambat/340c2a14d3a0745cac33378d457ed104 to your computer and use it in GitHub Desktop.
Laravel 8 - AWS Elastic Beanstalk Linux Distro - Use Laravel Scheduler - Confirmed Working Oct 16 2020.
files:
"/etc/cron.d/schedule_run":
mode: "000644"
owner: root
group: root
content: |
* * * * * root export $(cat /opt/elasticbeanstalk/deployment/env | xargs) && /usr/bin/php /var/www/html/artisan schedule:run &> /tmp/schedule_run.log
commands:
remove_old_cron:
command: "rm -f /etc/cron.d/*.bak"
#Be sure in your file there is one empty line after the last line of the file. Delete this line though.
<?php
// File located in App\Console\Kernel.php
namespace App\Console;
use Log;
use App\Helpers\BackgroundWorker;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
//
];
protected function scheduleTimezone() {
return 'America/Los_Angeles';
}
protected function schedule(Schedule $schedule) {
$schedule->call(function(){
BackgroundWorker::do_action();
})
->name('bgworker:do_action_one')
->weeklyOn(5, '17:00') // Fridays at 5PM
$schedule->call(function(){
BackgroundWorker::do_action_two();
})
->name('bgworker:do_action_two')
->hourly()
->between('9:00', '18:00'); // run hourly between 9AM-6PM
}
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
@timothycarambat
Copy link
Author

There is so much information online about how to schedule:run on laravel but a lot of it is incorrect. This gist is 100% confirmed to be working for Laravel 8 on AWS Elasticbeanstalk Linux AMI.

This will execute the schedule run command every minute and output that to a /tmp/ file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment