function notifications_process in Notifications 5
Same name and namespace in other branches
- 6 notifications.cron.inc \notifications_process()
- 6.2 notifications.cron.inc \notifications_process()
- 6.3 notifications.cron.inc \notifications_process()
Controls and checks limits for queue processing It can be used by other modules to add their own limits here, like number of sms sent, etc...
Parameters
$op: 'start' => Start the counters 'cron' => Special time adjustment for cron operations 'init' => Start a new counter with $value limit 'option' => Sets /gets options
- debug
- output Enables output for admin page
Return value
TRUE if we are yet under the processing limits
5 calls to notifications_process()
- notifications_admin_queue_process in ./
notifications.admin.inc - Admin manual queue processing
- notifications_message_send in ./
notifications.cron.inc - Message sending
- notifications_process_queue in ./
notifications.cron.inc - Process subscriptions queue
- notifications_process_run in ./
notifications.cron.inc - Function to be called on cron by the main notifications_cron
- notifications_process_send in ./
notifications.cron.inc - Message delivery.
File
- ./
notifications.cron.inc, line 131
Code
function notifications_process($op = 'check', $name = NULL, $value = NULL) {
static $limit = array(), $options = array();
static $current = array(
'message' => 0,
'step' => 0,
);
switch ($op) {
case 'start':
$defaults = variable_get('notifications_process_limit', array(
'time' => 0,
'message' => 0,
'row' => 0,
'percent' => 0,
));
foreach ($defaults as $name => $value) {
if ($value && !isset($limit[$name])) {
$limit[$name] = $value;
}
}
break;
case 'cron':
// Calculate time limit. We get the smaller of all these times in seconds
// There's an issue with poormanscron not setting the cron semaphore so it will default to current time
$timelimit = array();
$cronstart = variable_get('cron_semaphore', time());
// Max execution time may be zero meaning no limit, then no limits based on this
if ($maxtime = ini_get('max_execution_time')) {
$timelimit[] = $cronstart + $maxtime - NOTIFICATIONS_TIME_MARGIN;
if ($limit['percent']) {
$timelimit[] = time() + $maxtime * $limit['percent'] / 100;
unset($limit['percent']);
}
}
// This is an absolute limit, applies always if set
if ($limit['time']) {
$timelimit[] = time() + $limit['time'];
}
if ($timelimit) {
$limit['time'] = min($timelimit);
}
break;
case 'init':
$current[$name] = 0;
$limit[$name] = $value;
break;
case 'count':
$value = $value ? $value : 1;
isset($current[$name]) ? $current[$name] += $value : ($current[$name] = $value);
break;
case 'option':
if (isset($value)) {
$options[$name] = $value;
}
return $options[$name];
}
$current['time'] = time();
// Check all limits till we find a false one
foreach ($limit as $name => $value) {
if ($value && !empty($current[$name]) && $current[$name] >= $value) {
watchdog('notifications', t('Reached processing limit on queue processing: %name = %value', array(
'%name' => $name,
'%value' => $value,
)));
return FALSE;
}
}
return TRUE;
}