You are here

abstract class LauncherBase in Ultimate Cron 8.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.

Hierarchy

Expanded class hierarchy of LauncherBase

1 file declares its use of LauncherBase
SerialLauncher.php in src/Plugin/ultimate_cron/Launcher/SerialLauncher.php

File

src/Launcher/LauncherBase.php, line 43

Namespace

Drupal\ultimate_cron\Launcher
View source
abstract class LauncherBase extends CronPlugin implements LauncherInterface {

  /**
   * {@inheritdoc}
   */
  public function isLockedMultiple(array $jobs) {
    $lock_ids = array();
    foreach ($jobs as $name => $job) {
      $lock_ids[$name] = $this
        ->isLocked($job);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function launchJobs(array $jobs) {
    foreach ($jobs as $job) {
      if ($job
        ->isScheduled()) {
        $job
          ->launch();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function formatRunning(CronJobInterface $job) {
    $file = drupal_get_path('module', 'ultimate_cron') . '/icons/hourglass.png';
    $status = [
      '#theme' => 'image',
      '#uri' => $file,
    ];
    $title = t('running');
    return array(
      $status,
      $title,
    );
  }

  /**
   * {@inheritdoc}
   */
  public function formatUnfinished(CronJobInterface $job) {
    $file = drupal_get_path('module', 'ultimate_cron') . '/icons/lock_open.png';
    $status = [
      '#theme' => 'image',
      '#uri' => $file,
    ];
    $title = t('unfinished but not locked?');
    return array(
      $status,
      $title,
    );
  }

  /**
   * {@inheritdoc}
   */
  public function formatProgress(CronJobInterface $job, $progress) {
    $progress = $progress ? sprintf("(%d%%)", round($progress * 100)) : '';
    return $progress;
  }

  /**
   * {@inheritdoc}
   */
  public function initializeProgress(CronJobInterface $job) {
    \Drupal::service('ultimate_cron.progress')
      ->setProgress($job
      ->id(), FALSE);
  }

  /**
   * {@inheritdoc}
   */
  public function finishProgress(CronJobInterface $job) {
    \Drupal::service('ultimate_cron.progress')
      ->setProgress($job
      ->id(), FALSE);
  }

  /**
   * {@inheritdoc}
   */
  public function getProgress(CronJobInterface $job) {
    return \Drupal::service('ultimate_cron.progress')
      ->getProgress($job
      ->id());
  }

  /**
   * {@inheritdoc}
   */
  public function getProgressMultiple(array $jobs) {
    return \Drupal::service('ultimate_cron.progress')
      ->getProgressMultiple(array_keys($jobs));
  }

  /**
   * {@inheritdoc}
   */
  public function setProgress(CronJobInterface $job, $progress) {
    \Drupal::service('ultimate_cron.progress')
      ->setProgress($job
      ->id(), $progress);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CronPlugin::$globalOptions public static property
CronPlugin::$instances public static property
CronPlugin::$multiple public static property 1
CronPlugin::$weight public property
CronPlugin::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 4
CronPlugin::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
CronPlugin::cleanForm public function Clean form of empty fallback values.
CronPlugin::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration 4
CronPlugin::drupal_array_remove_nested_value public function Modified version drupal_array_get_nested_value().
CronPlugin::fallbackalize public function Process fallback form parameters.
CronPlugin::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
CronPlugin::getGlobalOption public static function Get global plugin option.
CronPlugin::getGlobalOptions public static function Get all global plugin options.
CronPlugin::getPluginTypes public static function Returns a list of plugin types.
CronPlugin::isValid public function Default plugin valid for all jobs. 1
CronPlugin::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
CronPlugin::setGlobalOption public static function Set global plugin option.
CronPlugin::settingsLabel public function Get label for a specific setting. 1
CronPlugin::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
CronPlugin::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 1
CronPlugin::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 2
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
LauncherBase::finishProgress public function Default implementation of finishProgress(). Overrides LauncherInterface::finishProgress
LauncherBase::formatProgress public function Default implementation of formatProgress(). Overrides LauncherInterface::formatProgress
LauncherBase::formatRunning public function Format running state. Overrides LauncherInterface::formatRunning
LauncherBase::formatUnfinished public function Format unfinished state. Overrides LauncherInterface::formatUnfinished
LauncherBase::getProgress public function Default implementation of getProgress(). Overrides LauncherInterface::getProgress
LauncherBase::getProgressMultiple public function Default implementation of getProgressMultiple(). Overrides LauncherInterface::getProgressMultiple
LauncherBase::initializeProgress public function Default implementation of initializeProgress(). Overrides LauncherInterface::initializeProgress
LauncherBase::isLockedMultiple public function Fallback implementation of multiple lock check. Overrides LauncherInterface::isLockedMultiple 1
LauncherBase::launchJobs public function Default implementation of jobs launcher. Overrides LauncherInterface::launchJobs 1
LauncherBase::setProgress public function Default implementation of setProgress(). Overrides LauncherInterface::setProgress
LauncherInterface::isLocked public function Check if a job is locked. 1
LauncherInterface::launch public function Launch job. 1
LauncherInterface::lock public function Lock job. 1
LauncherInterface::unlock public function Unlock a lock. 1
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.