[feature/system-cron] Try to work around stealth cron locks

Try to work around stealth cron locks resulting from fatal errors during cron processing.

PHPBB3-9596
This commit is contained in:
Oleg Pudeyev 2010-05-09 14:58:45 -04:00
parent d6fcea23a4
commit 5c03040ddd

View file

@ -48,17 +48,19 @@ function do_cron($run_tasks)
garbage_collection(); garbage_collection();
} }
$cron_lock = new cron_lock; // Thanks to various fatal errors and lack of try/finally, it is quite easy to leave
if ($cron_lock->lock()) // the cron lock locked, especially when working on cron-related code.
{ //
// Attempt to alleviate the problem by doing setup outside of the lock as much as possible.
//
// If DEBUG_EXTRA is defined and cron lock cannot be obtained, a message will be printed.
if ($config['use_system_cron']) if ($config['use_system_cron'])
{ {
$use_shutdown_function = false; $use_shutdown_function = false;
include($phpbb_root_path . 'includes/cron/cron_manager.' . $phpEx); include($phpbb_root_path . 'includes/cron/cron_manager.' . $phpEx);
$cron = new cron_manager; $cron = new cron_manager;
$run_tasks = $cron->find_all_ready_tasks();
} }
else else
{ {
@ -66,7 +68,17 @@ if ($cron_lock->lock())
$use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false; $use_shutdown_function = (@function_exists('register_shutdown_function')) ? true : false;
output_image(); output_image();
}
$cron_lock = new cron_lock;
if ($cron_lock->lock())
{
if ($config['use_system_cron'])
{
$run_tasks = $cron->find_all_ready_tasks();
}
else
{
// If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing // If invalid task is specified, empty $run_tasks is passed to do_cron which then does nothing
$run_tasks = array(); $run_tasks = array();
$task = $cron->find_task($cron_type); $task = $cron->find_task($cron_type);
@ -95,3 +107,10 @@ if ($cron_lock->lock())
do_cron($run_tasks); do_cron($run_tasks);
} }
} }
else
{
if (defined('DEBUG_EXTRA'))
{
echo "Could not obtain cron lock.";
}
}