add command indexer:schedule

This commit is contained in:
Irfan 2020-09-09 00:32:32 +05:00
parent f7342eea93
commit 542d779204
3 changed files with 96 additions and 2 deletions

View File

@ -16,7 +16,7 @@ class CommonIndexing extends Command
{
/**
* The name and signature of the console command.
*
*`
* @var string
*/
protected $signature = 'indexing:start';

View File

@ -0,0 +1,92 @@
<?php
namespace App\Console\Commands\Indexer;
use App\Http\HttpHelper;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Jikan\Request\Schedule\ScheduleRequest;
class ScheduleIndexer extends Command
{
/**
* The name and signature of the console command.
*`
* @var string
*/
protected $signature = 'indexer:schedule';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Index anime schedule';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
echo "Note: ScheduleIndexer makes sure anime currently airing are upto update so the schedules endpoint returns proper information\n\n";
/**
* Schedule
*/
echo "Fetching Schedule...\n";
$results = \json_decode(
app('SerializerV4')->serialize(
app('JikanParser')
->getSchedule(new ScheduleRequest()),
'json'
),
true
);
if (HttpHelper::hasError($results)) {
echo "FAILED: {$results->original['error']}\n";
return;
}
$anime = [];
foreach ($results as $day) {
foreach ($day as $entry) {
$anime[] = $entry;
}
}
$i = 1;
$itemCount = count($anime);
echo "Anime currently airing: {$itemCount} entries\n";
foreach ($anime as $entry) {
$url = env('APP_URL') . "/v4-alpha/anime/{$entry['mal_id']}";
file_get_contents($url);
//sleep(5); // prevent rate-limit
echo "Updating {$i}/{$itemCount} \r";
try {
} catch (\Exception $e) {
echo "[SKIPPED] Failed to fetch {$url}";
}
$i++;
}
echo str_pad("Indexing complete", 10).PHP_EOL;
}
}

View File

@ -8,6 +8,7 @@ use App\Console\Commands\BlacklistRemove;
use App\Console\Commands\ClearQueuedJobs;
use App\Console\Commands\CacheRemove;
use App\Console\Commands\CommonIndexing;
use App\Console\Commands\Indexer\ScheduleIndexer;
use App\Console\Commands\ModifyCacheDriver;
use App\Console\Commands\ModifyCacheMethod;
use Illuminate\Console\Scheduling\Schedule;
@ -29,7 +30,8 @@ class Kernel extends ConsoleKernel
BlacklistAdd::class,
BlacklistRemove::class,
BlacklistFlush::class,
CommonIndexing::class
CommonIndexing::class,
ScheduleIndexer::class
];
/**