public function UltimateCronSerialLauncher::runThread in Ultimate Cron 7.2
Run jobs in thread.
Parameters
string $lock_id: The lock id.
string $thread: The tread number.
array $jobs: The UltimateCronJobs to run.
1 call to UltimateCronSerialLauncher::runThread()
- UltimateCronSerialLauncher::launchJobs in plugins/
ultimate_cron/ launcher/ serial.class.php - Launch manager.
File
- plugins/
ultimate_cron/ launcher/ serial.class.php, line 342 - Serial cron job launcher for Ultimate Cron.
Class
- UltimateCronSerialLauncher
- Ultimate Cron launcher plugin class.
Code
public function runThread($lock_id, $thread, $jobs) {
$this->currentThread = $thread;
$this->currentThreadLockId = $lock_id;
$class = _ultimate_cron_get_class('lock');
$lock_name = 'ultimate_cron_serial_launcher_' . $thread;
foreach ($jobs as $job) {
$settings = $job
->getSettings($this->type);
switch ($settings['thread']) {
case 'any':
$settings['thread'] = $thread;
break;
case 'fixed':
$settings['thread'] = $job
->getUniqueID() % $settings['max_threads'] + 1;
break;
}
if ((!self::getGlobalOption('thread') || $settings['thread'] == $thread) && $job
->isScheduled()) {
$job
->launch();
// Be friendly, and check if someone else has taken the lock.
// If they have, bail out, since someone else is now handling
// this thread.
if ($current_lock_id = $class::isLocked($lock_name)) {
if ($current_lock_id !== $lock_id) {
return;
}
}
else {
// If lock is free, then take the lock again.
$lock_id = $class::lock($lock_name);
if (!$lock_id) {
// Race-condition, someone beat us to it.
return;
}
}
}
}
}