You are here

background_process.admin.inc in Background Process 7.2

File

background_process.admin.inc
View source
<?php

/**
 * @file
 */

/**
 * FAPI definition for settings page.
 */
function background_process_settings_form() {
  $form = array();
  $form['background_process_cleanup_age'] = array(
    '#type' => 'textfield',
    '#title' => t('Cleanup age'),
    '#description' => t('Unlock processes that have been more than X seconds to start.'),
    '#default_value' => variable_get('background_process_cleanup_age', BACKGROUND_PROCESS_CLEANUP_AGE),
  );
  $form['background_process_running_cleanup_age'] = array(
    '#type' => 'textfield',
    '#title' => t('Cleanup age for running jobs'),
    '#description' => t('Unlock processes that have been running for more than X seconds.'),
    '#default_value' => variable_get('background_process_running_cleanup_age', BACKGROUND_PROCESS_RUNNING_CLEANUP_AGE),
  );
  $form['background_process_queue_cleanup_age'] = array(
    '#type' => 'textfield',
    '#title' => t('Cleanup age for queued jobs'),
    '#description' => t('Unlock queued processes that have been more than X seconds to start.'),
    '#default_value' => variable_get('background_process_queue_cleanup_age', BACKGROUND_PROCESS_QUEUE_CLEANUP_AGE),
  );
  $form['background_process_result_cleanup_age'] = array(
    '#type' => 'textfield',
    '#title' => t('Cleanup age for results'),
    '#description' => t('Removed background process results older than X seconds..'),
    '#default_value' => variable_get('background_process_result_cleanup_age', BACKGROUND_PROCESS_RESULT_CLEANUP_AGE),
  );
  $options = background_process_get_service_hosts();
  foreach ($options as $key => &$value) {
    $new = empty($value['description']) ? $key : $value['description'];
    $new .= ' (' . background_process_get_service_host_title($value) . ')';
    $value = $new;
  }
  $form['background_process_default_service_host'] = array(
    '#type' => 'select',
    '#title' => t('Default service host'),
    '#description' => t('The default service host to use'),
    '#options' => $options,
    '#default_value' => variable_get('background_process_default_service_host', 'default'),
  );
  $options = background_process_get_service_groups();
  foreach ($options as $key => &$value) {
    $value = (empty($value['description']) ? $key : $value['description']) . ' (' . join(',', $value['hosts']) . ')';
  }
  $form['background_process_default_service_group'] = array(
    '#type' => 'select',
    '#title' => t('Default service group'),
    '#description' => t('The default service group to use.'),
    '#options' => $options,
    '#default_value' => variable_get('background_process_default_service_group', 'default'),
  );
  $form = system_settings_form($form);

  // Add determine button and make sure all the buttons are shown last.
  $form['buttons']['#weight'] = 1000;
  $form['buttons']['determine'] = array(
    '#value' => t("Determine default service host"),
    '#description' => t('Tries to determine the default service host.'),
    '#type' => 'submit',
    '#submit' => array(
      'background_process_settings_form_determine_submit',
    ),
  );
  return $form;
}

/**
 * Submit handler for determining default service host
 */
function background_process_settings_form_determine_submit($form, &$form_state) {
  background_process_determine_and_save_default_service_host();
}

/**
 * Overview of background processes.
 */
function background_process_overview_page() {
  $processes = BackgroundProcess::loadAll();
  $data = array();
  foreach ($processes as $process) {
    $data[] = array(
      $process
        ->getHandle(),
      $process->callback,
      $process->uid,
      $process->service_host,
      format_date((int) $process
        ->getStartTime(), 'custom', 'Y-m-d H:i:s'),
      $process
        ->getProgress() >= 0 ? sprintf("%.02f%%", $process
        ->getProgress() * 100) : t('N/A'),
      l(t('Unlock'), 'background-process/unlock/' . $process->pid, array(
        'attributes' => array(
          'class' => 'button-unlock',
        ),
        'query' => drupal_get_destination(),
      )),
    );
  }
  $header = array(
    'Handle',
    'Callback',
    'User',
    'Host',
    'Start time',
    'Progress',
    '',
  );
  $output = '';
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $data,
    'class' => 'background-process-overview',
  ));
  return $output;
}
function background_process_dispatchers_form() {
  $form = array();
  $form = system_settings_form($form);
  return $form;
}
function background_process_http_dispatcher_form() {
  $form = array();
  $form['background_process_service_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Service timeout'),
    '#description' => t('Timeout for service call in seconds (0 = disabled)'),
    '#default_value' => variable_get('background_process_service_timeout', BACKGROUND_PROCESS_SERVICE_TIMEOUT),
  );
  $form['background_process_connection_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Connection timeout'),
    '#description' => t('Timeout for connection in seconds'),
    '#default_value' => variable_get('background_process_connection_timeout', BACKGROUND_PROCESS_CONNECTION_TIMEOUT),
  );
  $form['background_process_stream_timeout'] = array(
    '#type' => 'textfield',
    '#title' => t('Stream timeout'),
    '#description' => t('Timeout for stream in seconds'),
    '#default_value' => variable_get('background_process_stream_timeout', BACKGROUND_PROCESS_STREAM_TIMEOUT),
  );
  $form = system_settings_form($form);
  return $form;
}
function background_process_drush_dispatcher_form() {
  $form = array();
  $form['background_process_drush_cmd'] = array(
    '#type' => 'textfield',
    '#title' => t('Location of drush command'),
    '#description' => t('Full path of drush file name'),
    '#default_value' => variable_get('background_process_drush_cmd', BACKGROUND_PROCESS_DRUSH_CMD),
  );
  $form = system_settings_form($form);
  return $form;
}
function background_process_queue_dispatcher_form() {
  $form = array();
  $form['background_process_queue_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Default queue name'),
    '#description' => t('Name of the default queue to use for background processes'),
    '#default_value' => variable_get('background_process_queue_name', BACKGROUND_PROCESS_QUEUE_NAME),
  );
  $form = system_settings_form($form);
  return $form;
}