diff options
| author | horus | 2022-11-17 19:57:52 +0100 |
|---|---|---|
| committer | horus | 2022-11-17 19:57:52 +0100 |
| commit | f4d0db3c67127919f431459aa1e430cab4e6d380 (patch) | |
| tree | 8d3cb288ccac34e108350543352fafc953d7ebe4 | |
| parent | f2e76ff110f531703f2c4f400e1fa285ee05ad94 (diff) | |
| download | senpai-f4d0db3c67127919f431459aa1e430cab4e6d380.tar.gz | |
Change scheduler from closures to artisan commands
| -rw-r--r-- | app/Console/Commands/CheckImage.php | 36 | ||||
| -rw-r--r-- | app/Console/Commands/SaveSeasonAiring.php | 43 | ||||
| -rw-r--r-- | app/Console/Commands/SaveStats.php | 37 | ||||
| -rw-r--r-- | app/Console/Commands/SaveTopAnimeEnhance.php | 43 | ||||
| -rw-r--r-- | app/Console/Commands/SetWatchingCalender.php | 41 | ||||
| -rw-r--r-- | app/Console/Kernel.php | 118 | ||||
| -rw-r--r-- | app/Libraries/Background.php | 6 |
7 files changed, 221 insertions, 103 deletions
diff --git a/app/Console/Commands/CheckImage.php b/app/Console/Commands/CheckImage.php new file mode 100644 index 0000000..fcd6d4a --- /dev/null +++ b/app/Console/Commands/CheckImage.php @@ -0,0 +1,36 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use App\Libraries\Background; + +class CheckImage extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'anime:checkImage'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Fix broken image links'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $background = new Background(); + echo "checkImage()\n"; + $background->checkImage(); + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/SaveSeasonAiring.php b/app/Console/Commands/SaveSeasonAiring.php new file mode 100644 index 0000000..5bee978 --- /dev/null +++ b/app/Console/Commands/SaveSeasonAiring.php @@ -0,0 +1,43 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use App\Libraries\Background; + +class SaveSeasonAiring extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'anime:saveSeasonAiring'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Save seasonal anime and airing status'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $background = new Background(); + echo "SaveSeason(): \n"; + $background->saveSeason(); + sleep(10); + echo "\ncheckIfIsAiring(): \n"; + $background->checkIfIsAiring(); + sleep(10); + echo "\nsaveAiringForAll(): \n"; + $background->saveAiringForAll(); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/SaveStats.php b/app/Console/Commands/SaveStats.php new file mode 100644 index 0000000..3466812 --- /dev/null +++ b/app/Console/Commands/SaveStats.php @@ -0,0 +1,37 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use App\Libraries\Background; + +class SaveStats extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'anime:saveStats'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Daily task to save Stats'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $background = new Background(); + if ( $background->saveAnimeStats() ) { + return Command::SUCCESS; + } + return Command::FAILURE; + } +} diff --git a/app/Console/Commands/SaveTopAnimeEnhance.php b/app/Console/Commands/SaveTopAnimeEnhance.php new file mode 100644 index 0000000..f46602b --- /dev/null +++ b/app/Console/Commands/SaveTopAnimeEnhance.php @@ -0,0 +1,43 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use App\Libraries\Background; + +class SaveTopAnimeEnhance extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'anime:saveTopAnimeEnhance'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Save top/popular anime, enhancements and season details'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $background = new Background(); + echo "saveTopAnime()\n"; + $background->saveTopAnime(); + echo "saveTopAnimeByPopularity()\n"; + $background->saveTopAnimeByPopularity(); + echo"saveEnhancementForAll()\n"; + $background->saveEnhancementForAll(); + echo "addSeasonToAllAnime()\n"; + $background->addSeasonToAllAnime(); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/SetWatchingCalender.php b/app/Console/Commands/SetWatchingCalender.php new file mode 100644 index 0000000..9e4bfa7 --- /dev/null +++ b/app/Console/Commands/SetWatchingCalender.php @@ -0,0 +1,41 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; +use App\Libraries\Helper; + +class SetWatchingCalender extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'anime:setWatchingCalender'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Update anime to set watching status and populate calendar entries'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $helper = new Helper(); + #$helper->createUser( 'll-' ); + echo "setIsWatchingForAll(): \n"; + $helper->setIsWatchingForAll(); + echo "\nsetCalendarForAll(): \n"; + $helper->setCalendarForAll(); + + return Command::SUCCESS; + + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fc949d4..907ee4a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -5,12 +5,6 @@ namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; -use App\Libraries\AnimeSeason; -use App\Libraries\Helper; -use App\Libraries\Background; - -use App\Anime; - class Kernel extends ConsoleKernel { /** @@ -30,107 +24,29 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - // $schedule->command('inspire') - // ->hourly(); - - $schedule->call( function(){ - $background = new Background(); - $background->saveAnimeStats(); - })->everyThirtyMinutes()->name('saveStats2')->withoutOverlapping(); - #})->everyThirtyMinutes()->name('saveStats5')->withoutOverlapping(); - #})->everyMinute()->name('saveStats3')->withoutOverlapping(); - #})->everyMinute()->name('saveStats5'); - - $schedule->call( function(){ - $background = new Background(); - echo "SaveSeason(): \n"; - $background->saveSeason(); - sleep(10); - echo "\ncheckIfIsAiring(): \n"; - $background->checkIfIsAiring(); - sleep(10); - echo "\nsaveAiringForAll(): \n"; - $background->saveAiringForAll(); - })->dailyAt('18:30'); - #})->everyMinute(); - $schedule->call( function(){ - $helper = new Helper(); - #$helper->createUser( 'll-' ); - echo "setIsWatchingForAll(): \n"; - $helper->setIsWatchingForAll(); - echo "\nsetCalendarForAll(): \n"; - $helper->setCalendarForAll(); - })->twiceDaily(7, 19); - #})->everyMinute(); + $schedule->command("anime:saveStats") + ->everyThirtyMinutes()->name('saveStats') + ->emailOutputTo( env('STATUS_MAIL_ADDRESS') ) + #->everyMinute()->name('saveStats1'); + ->withoutOverlapping(); - $schedule->call( function(){ - $background = new Background(); - echo "saveTopAnime()\n"; - $background->saveTopAnime(); - echo "saveTopAnimeByPopularity()\n"; - $background->saveTopAnimeByPopularity(); - echo"saveEnhancementForAll()\n"; - $background->saveEnhancementForAll(); - echo "addSeasonToAllAnime()\n"; - $background->addSeasonToAllAnime(); - })->weeklyOn(1, '15:30')->name('saveTopAnime')->withoutOverlapping(); - #})->everyMinute(); + $schedule->command("anime:saveSeasonAiring") + ->dailyAt('18:30') + ->emailOutputTo( env('STATUS_MAIL_ADDRESS') ); - $schedule->call( function(){ - $background = new Background(); - echo "checkImage()\n"; - $background->checkImage(); - })->weeklyOn(3, '18:00')->name('checkForBrokenThings')->withoutOverlapping(); - #})->everyMinute(); + $schedule->command("anime:setWatchingCalender") + ->twiceDaily(7, 19) + ->emailOutputTo( env('STATUS_MAIL_ADDRESS') ); - /* - $schedule->call( function(){ - $background = new Background(); - #$background->checkIfIsAiring(); - #$background->saveSeason(); - $background->saveEnhancementForAll(); - #$background->addSeasonToAllAnime(); - #$anime = Anime::where('mal_id', 40591)->get()->first(); - #$background->saveAiring( $anime ); - })->everyMinute()->name("enhance3")->withoutOverlapping(); - #})->everyMinute()->name("enhance6"); - #})->twiceDaily(9, 23); - */ + $schedule->command("anime:saveTopAnimeEnhance") + ->weeklyOn(1, '15:30')->name('saveTopAnime') + ->emailOutputTo( env('STATUS_MAIL_ADDRESS') ); - /* - $schedule->call( function(){ - $background = new Background(); - echo "\ncheckIfIsAiring(): \n"; - $background->checkIfIsAiring(); - sleep(10); - echo "\nsaveAiringForAll(): \n"; - $background->saveAiringForAll(); - #$background->checkIfIsAiring(); - #$background->checkImage(); - #$background->saveTopAnimeByPopularity(); - #$anime = Anime::where('mal_id', 40591)->get()->first(); - #$background->saveAiring( $anime ); - #echo"saveEnhancementForAll()\n"; - #$background->saveEnhancementForAll(); - })->everyMinute()->name('c4')->withoutOverlapping(); - #})->dailyAt('3:00')->name('saveTopAnimeByPopularity')->withoutOverlapping(); - #})->everyMinute()->name('saveTopAnimeByPopularity2')->withoutOverlapping(); - */ - /* - $schedule->call( function(){ - $background = new Background(); - echo "saveAiringForAll(): \n"; - $background->saveAiringForAll(); + $schedule->command("anime:checkImage") + ->weeklyOn(3, '18:00')->name('checkForBrokenThings') + ->emailOutputTo( env('STATUS_MAIL_ADDRESS') ); - $helper = new Helper(); - #$helper->createUser( 'll-' ); - echo "setIsWatchingForAll(): \n"; - #$helper->setIsWatchingForAll(); - echo "\nsetCalendarForAll(): \n"; - $helper->setCalendarForAll(); - })->everyMinute()->name('c8')->withoutOverlapping(); - */ } /** diff --git a/app/Libraries/Background.php b/app/Libraries/Background.php index 3f8ea5c..8cd8f07 100644 --- a/app/Libraries/Background.php +++ b/app/Libraries/Background.php @@ -166,8 +166,8 @@ class Background { } if ( 3 < $failure ) { - echo "Got " . $failure . " failures and " . $counter . " entries. Returning...\n"; - return; + echo "Got " . $failure . " failures and " . $counter . " entries. Last entry was: " . $entry->mal_id . " Returning...\n"; + return false; } $animeDetail = AnimeDetails::where('mal_id', $entry->mal_id); @@ -204,6 +204,8 @@ class Background { if ( 0 < $counter ) { echo "Got stats for " . $counter . " anime.\n"; } + + return true; } public function checkIfIsAiring() { |
