In Laravel 9, what is the default value of the maximum number of attempts at the queue task, such as the default value of the maximum number of attempts?
1. In Laravel 9, what is the default value of the maximum number of attempts for the queue task? Decided to try to verify, the implementation in the task class is as follows
public $timeout = 10;
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(2);
Log::info(
'handle',
[
date('Y-m-d H:i:s')
]
);
sss();
}
2. The print log is as follows
[2024-05-11 05:56:47] local.INFO: handle ["2024-05-11 05:56:47"]
3. The maximum number of attempts to define the task class itself is 1, and the implementation in the task class is as follows. The last printed log is the same result as $TRIES is not set. Conclusion: The maximum number of attempts is default to 1
public $tries = 1;
public $timeout = 10;
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(2);
Log::info(
'handle',
[
date('Y-m-d H:i:s')
]
);
sss();
}
[2024-05-11 06:04:02] local.INFO: handle ["2024-05-11 06:04:02"]
The maximum number of attempts to define the task class itself is 0, and the implementation in the task class is as follows. There are more than 40 logs printed at the end, and when the description is set to 0, the maximum number of attempts is unlimited times. Figure 1, Figure 2
public $tries = 0;
public $timeout = 10;
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(2);
Log::info(
'handle0',
[
date('Y-m-d H:i:s')
]
);
sss();
}
5. The maximum number of attempts to define the task class itself is 5, and the implementation in the task class is as follows. The last printed logs have 5 logs, indicating that when set to 5, the maximum number of attempts is 5 times. After the first 4 failures (fail is orange), you will continue to try, and it will not really fail until the 5th attempt (fail is red). Figure 3, Figure 4
public $tries = 5;
public $timeout = 10;
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(2);
Log::info(
'handle5',
[
date('Y-m-d H:i:s')
]
);
sss();
}



