You are here

function rec_transfer_download in Recommender API 7.4

Same name and namespace in other branches
  1. 6.3 rec_transfer/rec_transfer.module \rec_transfer_download()
  2. 7.5 rec_transfer/rec_transfer.module \rec_transfer_download()
1 call to rec_transfer_download()
rec_transfer_handle_commands in rec_transfer/rec_transfer.module
2 string references to 'rec_transfer_download'
rec_transfer_cron_queue_info in rec_transfer/rec_transfer.module
Implements hook_cron_queue_info().
rec_transfer_handle_commands in rec_transfer/rec_transfer.module

File

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

Code

function rec_transfer_download($command) {
  $command_id = $command['command_id'];
  $recommender_id = $command['recommender_id'];

  // if command_id doesn't exist anymore, simply ignore the rest of the code.
  // attention: perhaps need to check 'recommender_id' too.
  $num = db_query('SELECT COUNT(id) FROM {async_command} WHERE id=:id', array(
    ':id' => $command_id,
  ))
    ->fetchField();
  if ($num != 1) {
    return;
  }

  // check whether the service is finished or not.
  $status_check = rec_transfer_check_service('status', array(
    'id' => $command_id,
  ));
  if (!$status_check['success']) {
    async_command_update_command($command_id, array(
      'status' => 'FAIL',
      'message' => 'Remote service is not successful running this command. Additional message: ' . $status_check['message'],
      'end' => time(),
    ));
    return;
  }
  if (isset($status_check['status']) && $status_check['status'] == 'OKOK') {

    // download file.
    $s1 = rec_transfer_import_results('similarity', $command_id, $recommender_id);
    $s2 = rec_transfer_import_results('prediction', $command_id, $recommender_id);
    if ($s1 && $s2) {
      async_command_update_command($command_id, array(
        'status' => 'OKOK',
        'message' => 'Command running successful. Message from remote service: ' . $status_check['message'],
        'end' => time(),
      ));
    }
    else {

      // FIXME: retry download. don't need to recompute everything again.
      async_command_update_command($command_id, array(
        'status' => 'FAIL',
        'message' => 'Cannot download or import recommendations from remote service. Consider retry.',
        'end' => time(),
      ));
    }
  }
  else {
    $options = array(
      'message' => 'Message from remote service: ' . $status_check['message'],
      'checkpoint' => time(),
    );
    if (!empty($status_check['status'])) {
      $options['status'] = $status_check['status'];
    }
    async_command_update_command($command_id, $options);
  }
}