You are here

function dba_statpack_batch_snapshot in Database Administration 7

1 string reference to 'dba_statpack_batch_snapshot'
dba_statpack_batch_setup in ./dba.statpack.inc

File

./dba.statpack.inc, line 89

Code

function dba_statpack_batch_snapshot($interval, &$context) {

  // Prepare to loop until it's time to take another snapshot.
  if (empty($context['sandbox'])) {

    // re-use code from dba_report
    $context['results'][] = dba_invoke_driver_specific('status', NULL, 'report');
    $context['sandbox']['time'] = time();
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = $interval;
  }
  sleep(1);
  $context['sandbox']['progress']++;
  $current_time = time();
  $remaining = $interval - ($current_time - $context['sandbox']['time']);
  $context['message'] = t('Taking next snapshot in %time seconds', array(
    '%time' => $remaining,
  ));
  $context['finished'] = ($current_time - $context['sandbox']['time']) / $interval;
  if ($remaining <= 0) {
    $context['results'][] = dba_invoke_driver_specific('status', NULL, 'report');
    $_SESSION['dba_statpack_interval'] = $interval;
  }
}