You are here

function video_cron in Video 7.2

Same name and namespace in other branches
  1. 6.5 video.module \video_cron()
  2. 6.4 video.module \video_cron()
  3. 7 video.module \video_cron()

Implements hook_cron().

2 calls to video_cron()
VideoSchedulingTestCase::testQueueTimeout in tests/VideoScheduling.test
Tests for the queue timeout setting
VideoSchedulingTestCase::testTranscodeTimeout in tests/VideoScheduling.test
Tests for the transcode timeout setting
1 string reference to 'video_cron'
video_scheduling_admin_settings in modules/video_ui/video.admin.inc
Video cron admin settings

File

./video.module, line 232
All module hooks implementation can be found in this file.

Code

function video_cron() {
  if (!variable_get('video_cron', TRUE)) {
    return;
  }

  // Append up to video_ffmpeg_instances videos to the video queue.
  $videos = video_jobs::loadQueue();
  if (!empty($videos)) {
    $queue = DrupalQueue::get('video_queue');
    foreach ($videos as $video) {
      $queue
        ->createItem($video);
    }
  }

  // Mark items as FAILED that have been ACTIVE for more than video_transcode_timeout minutes and log this.
  $transcodetimeout = variable_get('video_transcode_timeout', 5);
  if (!empty($transcodetimeout)) {
    $limit = time() - $transcodetimeout * 60;
    $videos = db_query('SELECT f.fid FROM {video_queue} q INNER JOIN {file_managed} f ON (f.fid = q.fid) WHERE q.statusupdated < ? AND q.status = ?', array(
      $limit,
      VIDEO_RENDERING_ACTIVE,
    ))
      ->fetchAllKeyed(0, 0);
    if (!empty($videos)) {
      $list = array();
      foreach ($videos as $fid) {
        $video = video_jobs::load($fid);
        video_jobs::setFailed($video);
        $entity = video_utility::loadEntity($video->entity_type, $video->entity_id);
        $uri = entity_uri($video->entity_type, $entity);
        $list[] = l($video->filename, $uri['path'], $uri['options']) . ' (' . t('@status since @datetime', array(
          '@status' => t('active'),
          '@datetime' => format_date($video->statusupdated),
        )) . ')';
      }
      watchdog('video', 'The following videos were marked as %newstate because they have been in %oldstate state for more than @timeout minutes. To increase this limit, update the Video module scheduling @setting-name setting. !list', array(
        '%newstate' => 'failed',
        '%oldstate' => 'rendering active',
        '@timeout' => $transcodetimeout,
        '@setting-name' => t('Video transcode timeout'),
        '!list' => theme('item_list', array(
          'items' => $list,
        )),
      ), WATCHDOG_WARNING, l(t('configure'), 'admin/config/media/video/scheduling'));
    }
  }

  // Mark items as PENDING that have been QUEUED for more than video_queue_timeout minutes and log this.
  $queuetimeout = variable_get('video_queue_timeout', 60);
  if (!empty($queuetimeout)) {
    $limit = time() - $queuetimeout * 60;
    $videos = db_query('SELECT f.fid, f.filename, q.entity_type, q.entity_id, q.statusupdated FROM {video_queue} q INNER JOIN {file_managed} f ON (f.fid = q.fid) WHERE q.statusupdated < ? AND q.status = ?', array(
      $limit,
      VIDEO_RENDERING_INQUEUE,
    ))
      ->fetchAllAssoc('fid');
    if (!empty($videos)) {
      db_update('video_queue')
        ->condition('fid', array_keys($videos), 'IN')
        ->fields(array(
        'status' => VIDEO_RENDERING_PENDING,
        'statusupdated' => time(),
      ))
        ->execute();
      $list = array();
      foreach ($videos as $video) {
        $entity = video_utility::loadEntity($video->entity_type, $video->entity_id);
        $uri = entity_uri($video->entity_type, $entity);
        $list[] = l($video->filename, $uri['path'], $uri['options']) . ' (' . t('@status since @datetime', array(
          '@status' => t('queued'),
          '@datetime' => format_date($video->statusupdated),
        )) . ')';
      }
      watchdog('video', 'The following videos were marked as %newstate because they have been in %oldstate state for more than @timeout minutes. To increase this limit, update the Video module scheduling @setting-name setting. !list', array(
        '%newstate' => 'rendering pending',
        '%oldstate' => 'queued',
        '@timeout' => $queuetimeout,
        '@setting-name' => t('Video queue timeout'),
        '!list' => theme('item_list', array(
          'items' => $list,
        )),
      ), WATCHDOG_NOTICE, l(t('configure'), 'admin/config/media/video/scheduling'));
    }
  }
}