mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
add command microcaching:service {enable/disable}
This commit is contained in:
parent
aaa9eaee74
commit
3ff68c4f17
@ -72,10 +72,10 @@ class CurrentSeasonIndexer extends Command
|
||||
file_get_contents($url);
|
||||
sleep(3); // prevent rate-limit
|
||||
|
||||
echo "Updating {$i}/{$itemCount} [{$entry['mal_id']} - {$entry['title']}] \r";
|
||||
echo "Updating {$i}/{$itemCount} {$url} [{$entry['mal_id']} - {$entry['title']}] \n";
|
||||
try {
|
||||
} catch (\Exception $e) {
|
||||
echo "[SKIPPED] Failed to fetch {$url}";
|
||||
echo "[SKIPPED] Failed to fetch {$url}\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
65
app/Console/Commands/ManageMicrocaching.php
Normal file
65
app/Console/Commands/ManageMicrocaching.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class ManageMicrocaching extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'microcaching:service {status}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enable or disable microcaching';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!\in_array($this->argument('status'), ['disable', 'enable'])) {
|
||||
$this->error('Only [enable/disable] allowed');
|
||||
return;
|
||||
}
|
||||
|
||||
$enabled = $this->argument('status') === 'enable';
|
||||
|
||||
if ($enabled === env('MICROCACHING')) {
|
||||
$this->error("MICROCASHING is already '{$this->argument('status')}'");
|
||||
return;
|
||||
}
|
||||
|
||||
$path = base_path('.env');
|
||||
|
||||
if (!file_exists($path)) {
|
||||
$this->error(".env does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
file_put_contents($path, str_replace(
|
||||
'MICROCACHING='.(env('MICROCACHING') ? 'true' : 'false'), 'MICROCACHING='.($enabled ? 'true' : 'false'), file_get_contents($path)
|
||||
));
|
||||
|
||||
$this->info("MICROCACHING: '{$this->argument('status')}'");
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ use App\Console\Commands\Indexer\AnimeScheduleIndexer;
|
||||
use App\Console\Commands\Indexer\CommonIndexer;
|
||||
use App\Console\Commands\Indexer\CurrentSeasonIndexer;
|
||||
use App\Console\Commands\Indexer\ScheduleIndexer;
|
||||
use App\Console\Commands\ManageMicrocaching;
|
||||
use App\Console\Commands\ModifyCacheDriver;
|
||||
use App\Console\Commands\ModifyCacheMethod;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
@ -32,7 +33,8 @@ class Kernel extends ConsoleKernel
|
||||
CacheRemove::class,
|
||||
CommonIndexer::class,
|
||||
AnimeScheduleIndexer::class,
|
||||
CurrentSeasonIndexer::class
|
||||
CurrentSeasonIndexer::class,
|
||||
ManageMicrocaching::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user