Skip to content

Commit

Permalink
#84 Added some log lines for scheduling, updated from Laravel 5.6 to …
Browse files Browse the repository at this point in the history
…Laravel 5.7.
  • Loading branch information
Wotuu committed Dec 4, 2018
1 parent 19c99f7 commit 561172c
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 122 deletions.
7 changes: 5 additions & 2 deletions app/Console/Kernel.php
Expand Up @@ -2,10 +2,10 @@

namespace App\Console;

use App\Jobs\ProcessRouteThumbnail;
use App\Logic\Scheduler\FindOutdatedThumbnails;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
Expand All @@ -26,9 +26,12 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
Log::channel('scheduler')->debug("Starting scheduler");

// $schedule->command('inspire')
// ->hourly();
// $schedule->call(new FindOutdatedThumbnails($schedule))->everyFiveMinutes();
$schedule->call(new FindOutdatedThumbnails);
Log::channel('scheduler')->debug("Finished scheduler");
}

/**
Expand Down
26 changes: 10 additions & 16 deletions app/Logic/Scheduler/FindOutdatedThumbnails.php
Expand Up @@ -10,38 +10,32 @@

use App\Jobs\ProcessRouteThumbnail;
use App\Models\DungeonRoute;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;

class FindOutdatedThumbnails
{

/**
* @var Schedule
*/
private $schedule;

/**
* FindOutdatedThumbnails constructor.
* @param Schedule $schedule
*/
public function __construct(Schedule $schedule)
{
$this->schedule = $schedule;
}

function __invoke()
{
Log::channel('scheduler')->debug(sprintf('Checking %s routes for thumbnails', DungeonRoute::all()->count()));

$processed = 0;
foreach (DungeonRoute::all() as $dungeonRoute) {
$updatedAt = Carbon::createFromTimeString($dungeonRoute->updated_at);
$thumbnailUpdatedAt = Carbon::createFromTimeString($dungeonRoute->thumbnail_updated_at);

// If the route has been updated in the past 30 minutes...
if ($updatedAt->addMinute(30)->isPast() &&
// Updated at is greater than the thumbnail updated at (don't keep updating thumbnails..
$updatedAt->greaterThan($thumbnailUpdatedAt)) {
// Set it for processing in a queue
ProcessRouteThumbnail::dispatch($dungeonRoute);

$processed++;
break;
}
}

Log::channel('scheduler')->debug(sprintf('Scheduled processing for %s routes', $processed));
}
}
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
"barryvdh/laravel-ide-helper": "^2.4",
"folklore/image": "0.3.*",
"jenssegers/agent": "^2.6",
"laravel/framework": "5.6.*",
"laravel/framework": "5.7.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.6",
"miraris/monolog-discord-handler": "^0.2.0",
Expand Down

0 comments on commit 561172c

Please sign in to comment.