You are here

function rec_transfer_download in Recommender API 6.3

Same name and namespace in other branches
  1. 7.4 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

File

rec_transfer/rec_transfer.module, line 119
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'];

  // 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, 0, 'Remote service is not successful running this command. Additional message: ' . $status_check['message'], 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, 1, 'Command running successful. Message from remote service: ' . $status_check['message'], time());
    }
    else {

      // FIXME: retry download. don't need to recompute everything again.
      async_command_update_command($command_id, 0, 'Cannot download or import recommendations from remote service. Consider retry.', time());
    }
  }

  // else {
  //   $options = array(
  //     'message' => 'Message from remote service: '. $status_check['message'],
  //     'checkpoint' => time(), // only update checkpoint. not end time.
  //   );
  //   if (!empty($status_check['status'])) {
  //     $options['status'] = $status_check['status'];
  //   }
  //   async_command_update_command($command_id, $options);
  // }
}