You are here

function rec_transfer_handle_commands in Recommender API 6.3

Same name and namespace in other branches
  1. 7.4 rec_transfer/rec_transfer.module \rec_transfer_handle_commands()
  2. 7.5 rec_transfer/rec_transfer.module \rec_transfer_handle_commands()
1 call to rec_transfer_handle_commands()
rec_transfer_cron in rec_transfer/rec_transfer.module
Implements hook_cron().

File

rec_transfer/rec_transfer.module, line 55
This is the module file for Recommender Data Transfer

Code

function rec_transfer_handle_commands($cron = FALSE) {
  if (is_null(variable_get('rec_transfer_apikey', NULL)) || is_null(variable_get('rec_transfer_endpoint', NULL))) {
    watchdog('rec_transfer', 'You must specify service endpoint and apikey.');
    return;
  }

  // retrieve the ping server commands
  $rows = db_query("SELECT id FROM {async_command} WHERE status IS NULL AND app='recommender' AND command='pingMe()'");
  while ($row = db_fetch_object($rows)) {
    $ready_check = rec_transfer_check_service('ready');
    if (!$ready_check['success']) {
      async_command_update_command($row->id, 0, 'Remote service is not ready. Additional message: ' . $ready_check['message'], time());
    }
    else {
      async_command_update_command($row->id, 1, 'Pong from remote service: ' . $ready_check['message'], time());
    }
  }

  // retrieve a list of commands waiting to be executed.
  $rows = db_query("SELECT id, eid FROM {async_command} WHERE status IS NULL AND app='recommender' AND command='runRecommender()'");
  while ($row = db_fetch_object($rows)) {
    $command = array(
      'command_id' => $row->id,
      'recommender_id' => $row->eid,
    );
    rec_transfer_upload($command);
  }

  // retrieve a list of commands pending or running, check status and download results if necessary
  $rows = db_query("SELECT id, eid FROM {async_command} WHERE status=2 AND app='recommender' AND command='runRecommender()'");
  while ($row = db_fetch_object($rows)) {
    $command = array(
      'command_id' => $row->id,
      'recommender_id' => $row->eid,
    );
    rec_transfer_download($command);
  }
}