1. In Laravel 9, what is the default value for the maximum number of attempts for a queued job? I decided to verify this. The implementation in the job 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 printed logs are as follows:
[2024-05-11 05:56:47] local.INFO: handle ["2024-05-11 05:56:47"]
3. I defined the maximum number of attempts for the job class itself as 1. The implementation in the job class is as follows. The final printed logs show the same result as when $tries is not set. Conclusion: the default maximum number of attempts is 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"]
4. I defined the maximum number of attempts for the job class itself as 0. The implementation in the job class is as follows. The final printed logs contain over 40 entries, indicating that when set to 0, the maximum number of attempts is unlimited. See Figure 1 and 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. I defined the maximum number of attempts for the job class itself as 5. The implementation in the job class is as follows. The final printed logs contain 5 entries, indicating that when set to 5, the maximum number of attempts is 5. After the first 4 failures (FAIL in orange), it continues to retry until the 5th attempt (FAIL in red), at which point it truly fails. See Figure 3 and 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();
}
