abstract class UltimateCronLauncher in Ultimate Cron 7.2
Abstract class for Ultimate Cron launchers.
A launcher is responsible for locking and launching/running a job.
Abstract methods: lock($job)
- Lock a job. This method must return the lock_id on success or FALSE on failure.
unlock($lock_id, $manual = FALSE)
- Release a specific lock id. If $manual is set, then the release was triggered manually by a user.
isLocked($job)
- Check if a job is locked. This method must return the current
- lock_id for the given job, or FALSE if it is not locked.
launch($job)
- This method launches/runs the given job. This method must handle the locking of job before launching it. Returns TRUE on successful launch, FALSE if not.
Important methods: isLockedMultiple($jobs)
- Check locks for multiple jobs. Each launcher should implement an optimized version of this method if possible.
launchJobs($jobs)
- Launches the jobs provided to it. A default implementation of this exists, but can be overridden. It is assumed that this function checks the jobs schedule before launching and that it also handles locking wrt concurrency for the launcher itself.
launchPoorman()
- Launches all scheduled jobs via the proper launcher for each jobs. This method only needs to be implemented if the launcher wishes to provide a poormans cron launching mechanism. It is assumed that the poormans cron launcher handles locking wrt concurrency, etc.
Hierarchy
- class \UltimateCronPlugin
- class \UltimateCronLauncher
Expanded class hierarchy of UltimateCronLauncher
3 string references to 'UltimateCronLauncher'
- background_process_legacy.inc in plugins/
ultimate_cron/ launcher/ background_process_legacy.inc - serial.inc in plugins/
ultimate_cron/ launcher/ serial.inc - ultimate_cron_ctools_plugin_type in ./
ultimate_cron.module - Implements hook_ctools_plugin_type().
File
- ./
ultimate_cron.plugin.inc, line 907 - Plugin framework for Ultimate Cron.
View source
abstract class UltimateCronLauncher extends UltimateCronPlugin {
/**
* Default settings.
*/
public function defaultSettings() {
return array();
}
/**
* Lock job.
*
* @param UltimateCronJob $job
* The job to lock.
*
* @return string
* Lock ID or FALSE.
*/
public abstract function lock($job);
/**
* Unlock a lock.
*
* @param string $lock_id
* The lock id to unlock.
* @param bool $manual
* Whether this is a manual unlock or not.
*
* @return bool
* TRUE on successful unlock.
*/
public abstract function unlock($lock_id, $manual = FALSE);
/**
* Check if a job is locked.
*
* @param UltimateCronJob $job
* The job to check.
*
* @return string
* Lock ID of the locked job, FALSE if not locked.
*/
public abstract function isLocked($job);
/**
* Launch job.
*
* @param UltimateCronJob $job
* The job to launch.
*
* @return bool
* TRUE on successful launch.
*/
public abstract function launch($job);
/**
* Fallback implementation of multiple lock check.
*
* Each launcher should implement an optimized version of this method
* if possible.
*
* @param array $jobs
* Array of UltimateCronJob to check.
*
* @return array
* Array of lock ids, keyed by job name.
*/
public function isLockedMultiple($jobs) {
$lock_ids = array();
foreach ($jobs as $name => $job) {
$lock_ids[$name] = $this
->isLocked($job);
}
return $lock_ids;
}
/**
* Run the job.
*
* @param UltimateCronJob $job
* The job to run.
*/
public function run($job) {
// Prevent session information from being saved while cron is running.
$original_session_saving = drupal_save_session();
drupal_save_session(FALSE);
// Force the current user to anonymous to ensure consistent permissions on
// cron runs.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$php_self = NULL;
try {
// Signal to whomever might be listening, that we're cron!
// @investigate Is this safe? (He asked knowingly ...)
$php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : '';
$_SERVER['PHP_SELF'] = 'cron.php';
$job
->invoke();
// Restore state.
$_SERVER['PHP_SELF'] = $php_self;
} catch (Throwable $e) {
// Restore state.
if (isset($php_self)) {
$_SERVER['PHP_SELF'] = $php_self;
}
ultimate_cron_watchdog_throwable('ultimate_cron', $e, 'Error running @name: @error', array(
'@name' => $job->name,
'@error' => (string) $e,
), WATCHDOG_ERROR);
} catch (Exception $e) {
// Restore state.
if (isset($php_self)) {
$_SERVER['PHP_SELF'] = $php_self;
}
watchdog_exception('ultimate_cron', $e, 'Error running @name: @error', array(
'@name' => $job->name,
'@error' => (string) $e,
), WATCHDOG_ERROR);
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session($original_session_saving);
}
/**
* Default implementation of jobs launcher.
*
* @param array $jobs
* Array of UltimateCronJob to launch.
*/
public function launchJobs($jobs) {
foreach ($jobs as $job) {
if ($job
->isScheduled()) {
$job
->launch();
}
}
}
/**
* Format running state.
*/
public function formatRunning($job) {
$file = drupal_get_path('module', 'ultimate_cron') . '/icons/hourglass.png';
$status = theme('image', array(
'path' => $file,
));
$title = t('running');
return array(
$status,
$title,
);
}
/**
* Format unfinished state.
*/
public function formatUnfinished($job) {
$file = drupal_get_path('module', 'ultimate_cron') . '/icons/lock_open.png';
$status = theme('image', array(
'path' => $file,
));
$title = t('unfinished but not locked?');
return array(
$status,
$title,
);
}
/**
* Default implementation of formatProgress().
*
* @param UltimateCronJob $job
* Job to format progress for.
*
* @return string
* Formatted progress.
*/
public function formatProgress($job, $progress) {
$progress = $progress ? sprintf("(%d%%)", round($progress * 100)) : '';
return $progress;
}
/**
* Default implementation of initializeProgress().
*
* @param UltimateCronJob $job
* Job to initialize progress for.
*/
public function initializeProgress($job) {
$class = _ultimate_cron_get_class('progress');
return $class::factory($job->name)
->setProgress(FALSE);
}
/**
* Default implementation of finishProgress().
*
* @param UltimateCronJob $job
* Job to finish progress for.
*/
public function finishProgress($job) {
$class = _ultimate_cron_get_class('progress');
return $class::factory($job->name)
->setProgress(FALSE);
}
/**
* Default implementation of getProgress().
*
* @param UltimateCronJob $job
* Job to get progress for.
*
* @return float
* Progress for the job.
*/
public function getProgress($job) {
$class = _ultimate_cron_get_class('progress');
return $class::factory($job->name)
->getProgress();
}
/**
* Default implementation of getProgressMultiple().
*
* @param UltimateCronJob $jobs
* Jobs to get progresses for, keyed by job name.
*
* @return array
* Progresses, keyed by job name.
*/
public function getProgressMultiple($jobs) {
$class = _ultimate_cron_get_class('progress');
return $class::getProgressMultiple(array_keys($jobs));
}
/**
* Default implementation of setProgress().
*
* @param UltimateCronJob $job
* Job to set progress for.
* @param float $progress
* Progress (0-1).
*/
public function setProgress($job, $progress) {
$class = _ultimate_cron_get_class('progress');
return $class::factory($job->name)
->setProgress($progress);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UltimateCronLauncher:: |
public | function |
Default settings. Overrides UltimateCronPlugin:: |
2 |
UltimateCronLauncher:: |
public | function | Default implementation of finishProgress(). | 1 |
UltimateCronLauncher:: |
public | function | Default implementation of formatProgress(). | |
UltimateCronLauncher:: |
public | function | Format running state. | 1 |
UltimateCronLauncher:: |
public | function | Format unfinished state. | |
UltimateCronLauncher:: |
public | function | Default implementation of getProgress(). | 1 |
UltimateCronLauncher:: |
public | function | Default implementation of getProgressMultiple(). | 1 |
UltimateCronLauncher:: |
public | function | Default implementation of initializeProgress(). | 1 |
UltimateCronLauncher:: |
abstract public | function | Check if a job is locked. | 2 |
UltimateCronLauncher:: |
public | function | Fallback implementation of multiple lock check. | 2 |
UltimateCronLauncher:: |
abstract public | function | Launch job. | 2 |
UltimateCronLauncher:: |
public | function | Default implementation of jobs launcher. | 2 |
UltimateCronLauncher:: |
abstract public | function | Lock job. | 2 |
UltimateCronLauncher:: |
public | function | Run the job. | |
UltimateCronLauncher:: |
public | function | Default implementation of setProgress(). | 1 |
UltimateCronLauncher:: |
abstract public | function | Unlock a lock. | 2 |
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public static | property | ||
UltimateCronPlugin:: |
public static | property | ||
UltimateCronPlugin:: |
public static | property | 1 | |
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | ||
UltimateCronPlugin:: |
public | property | 1 | |
UltimateCronPlugin:: |
public | function | Allow plugins to alter the allowed operations for a job. | 2 |
UltimateCronPlugin:: |
public | function | Clean form of empty fallback values. | |
UltimateCronPlugin:: |
public | function | A hook_cronapi() for plugins. | 1 |
UltimateCronPlugin:: |
public | function | A hook_cron_alter() for plugins. | 3 |
UltimateCronPlugin:: |
public | function | A hook_cron_post_invoke() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_launch() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_run() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_post_schedule() for plugins. | 1 |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_invoke() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_launch() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_run() for plugins. | |
UltimateCronPlugin:: |
public | function | A hook_cron_pre_schedule() for plugins. | 2 |
UltimateCronPlugin:: |
public static | function | Default settings form. | 1 |
UltimateCronPlugin:: |
public | function | Modified version drupal_array_get_nested_value(). | |
UltimateCronPlugin:: |
public static | function | Singleton factoryLogEntry. | |
UltimateCronPlugin:: |
public | function | Process fallback form parameters. | |
UltimateCronPlugin:: |
public | function | Format label for the plugin. | 1 |
UltimateCronPlugin:: |
public | function | Format verbose label for the plugin. | 1 |
UltimateCronPlugin:: |
public | function | Get default settings. | 1 |
UltimateCronPlugin:: |
public static | function | Get global plugin option. | |
UltimateCronPlugin:: |
public static | function | Get all global plugin options. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_alter() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_invoke() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_launch() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_run() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_post_schedule() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_invoke() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_launch() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_run() on plugins. | |
UltimateCronPlugin:: |
final public static | function | Invoke hook_cron_pre_schedule() on plugins. | |
UltimateCronPlugin:: |
public | function | Default plugin valid for all jobs. | 2 |
UltimateCronPlugin:: |
public static | function | Job settings form. | 1 |
UltimateCronPlugin:: |
public static | function | Job settings form submit handler. | 1 |
UltimateCronPlugin:: |
public static | function | Job settings form validate handler. | 1 |
UltimateCronPlugin:: |
public static | function | Set global plugin option. | |
UltimateCronPlugin:: |
public | function | Save settings to db. | |
UltimateCronPlugin:: |
public | function | Settings form. | 8 |
UltimateCronPlugin:: |
public | function | Settings form submit handler. | 3 |
UltimateCronPlugin:: |
public | function | Settings form validate handler. | 1 |
UltimateCronPlugin:: |
public | function | Get label for a specific setting. | 3 |
UltimateCronPlugin:: |
public | function | Signal page for plugins. | 2 |
UltimateCronPlugin:: |
public static | function | Remove a global plugin option. | |
UltimateCronPlugin:: |
public static | function | Remove all global plugin options. | |
UltimateCronPlugin:: |
public | function | Constructor. | 1 |