You are here

function commerce_stock_local_cron in Commerce Stock 8

Implements hook_cron().

File

modules/local_storage/commerce_stock_local.module, line 34
Commerce Stock Local module.

Code

function commerce_stock_local_cron() {
  $next = \Drupal::state()
    ->get('commerce_stock_local.update_level_next') ?: 0;
  $request_time = \Drupal::time()
    ->getRequestTime();
  if ($request_time >= $next) {
    $cron_run_mode = \Drupal::config('commerce_stock_local.cron')
      ->get('cron_run_mode');
    if ($cron_run_mode == 'legacy') {
      _commerce_stock_local_update_stock_level_queue_legacy();
    }
    else {
      _commerce_stock_local_update_stock_level_queue();
    }

    // Set the next run time.
    $interval = \Drupal::config('commerce_stock_local.cron')
      ->get('update_interval');
    \Drupal::state()
      ->set('commerce_stock_local.update_level_next', $request_time + $interval);
  }
}