To answer my own question... the scheduler wasn't running in forge. I had to add a new one to run schedule:run
Scheduled Commands run in Dev but not in Forge staging server
So I have my staging server on Forge. When ever I go to test things it is not running my kernel scheduled jobs.
here is what I have:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Models\League;
use Carbon\Carbon;
use App\Models\FantasyTeam;
use App\Models\DraftOrder;
use Symfony\Component\Process\Process;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$this->scheduleDraftOrderCommands($schedule);
$this->scheduleStartDraftCommands($schedule);
}
protected function scheduleDraftOrderCommands(Schedule $schedule)
{
$today = Carbon::now()->format('Y-m-d');
$leagues = League::where('draft_date','<>',null)
->where('draft_started',0)
->where('draft_date', '<', Carbon::now()->addMinutes(16)->toDateTimeString())
->where('online_draft',1)
->get();
if(!empty($leagues)){
foreach($leagues as $league){
$schedule->command('GenerateDraftOrder', ['--league_id' => $league->id])->name('GenerateDraftOrder '.$league->name);
}
}
}
protected function scheduleStartDraftCommands(Schedule $schedule)
{
$today = Carbon::now()->format('Y-m-d');
$leagues =League::where('draft_date','<>',null)
->where('draft_started',0)
->where('draft_date', '<', Carbon::now()->addSeconds(90)->toDateTimeString())
->where('online_draft',1)
->get();
if(!empty($leagues)){
foreach($leagues as $league){
$schedule->command('StartDraft', ['--league_id' => $league->id])->name('StartDraft '.$league->name)->runInBackground();
}
}
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
When I run on my local dev I do the following in the command line to simulate a cron:
while true; do php artisan schedule:run; sleep 60; done
it works flawlessly on my dev.
However, it won't work on my Forge staging server. Forge is supposed to have CRONs running by default.
I have php artisan clear:cache on the stage server to see if it was that. But it didn't help.
If I manually run... php artisan schedule:run via ssh it does what it is supposed to do.
It's like the cron isn't running on my Forge stage server. So my questions:
-
Should the above Kernel code run correctly?
-
Any suggestions for how I can get this to run properly on Forge?
Please or to participate in this conversation.