I used the task scheduling function in Ravel to create a random update of the quiz, but the task schedule should be working normally, but there is no change at all.Is the description of handle() in TimeQuiz.php strange?
If you write the same program in Controller.php, it works normally.
phpartisan schedule:run results
Running scheduled command: '/usr/bin/php' 'artisan' command:quiz>'/dev/null'2>&1
TimeQuiz.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
useApp\Quiz;
class TimeQuiz extensions Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature='command:quiz';
/**
* The console command description.
*
* @var string
*/
protected$description='TimeQuiz';
/**
* Create a new command instance.
*
* @return void
*/
public function__construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$quiz=Quiz::with('answer')
->inRandomOrder()
->get();
return$quiz;
}
}
Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;
class Kernel extensions ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\TimeQuiz'
];
/**
* Define the application's command schedule.
*
* @param\Illuminate\Console\Scheduling\Schedule$schedule
* @return void
*/
protected function schedule (Schedule$schedule)
{
$schedule->command('command:quiz')
->everyMinute()
->onSuccess(function(){
Log::info('success');
});
}
It's the same as doing nothing with the current handle().
Keep commands + schedules in cache forever.
$quiz=Quiz::with ('answer')
->inRandomOrder()
->get();
cache()->forever('quiz',$quiz);
Save it and take it out where you want it to be used.
$quiz=cache('quiz');
Save on the back (updated regularly on schedule) and take it out of the cache when using it, so it's fast.
This is an advantage, so in the case of this question, there is no point in executing it with a command.
If it's random, it's better to get it for each user's access, so there's no cache.
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.