function tripal_bulk_loader_progess_file_get_progress
2.x tripal_bulk_loader.module | tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress = TRUE) |
3.x tripal_bulk_loader.module | tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress = TRUE) |
1.x tripal_bulk_loader.module | tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress = TRUE) |
Get the progress of the current constant set from the progress file
When transactions are used, database updates to drupal cannot be made. Thus a separate method to keep track of progress was implemented: save a period to the file for each record successfully inserted; each line in the file represents a processed line.
Parameters
$job_id: The id of the tripal job to check the progress of
$node: The tripal_bulk_loader node associated with the job
Return value
An array with the following keys: num_lines = the number of lines in the file processed so far total_lines = the total number of lines in the input file percent_file = the percent the input file has been loaded num_records = the number of records successfully inserted
Related topics
2 calls to tripal_bulk_loader_progess_file_get_progress()
- drush_tripal_bulk_loader_tripal_loader_progress in tripal_bulk_loader/
tripal_bulk_loader.drush.inc - Code ran for the tripal-loader-progress drush command Display the progress of any running tripal bulk loading job.
- tripal_bulk_loader_load in tripal_bulk_loader/
tripal_bulk_loader.module - Implements node_load
File
- tripal_bulk_loader/
tripal_bulk_loader.module, line 544 - The functions for the Tripal bulk loader.
Code
function tripal_bulk_loader_progess_file_get_progress($job_id, $update_progress = TRUE) {
$filename = '/tmp/tripal_bulk_loader_progress-' . $job_id . '.out';
if (!file_exists($filename)) {
return (object) array();
}
$num_lines = trim($filename);
$num_records = trim($filename);
$job = db_fetch_object(db_query("SELECT j.*, b.file, b.file_has_header, c.num as num_constant_sets
FROM {tripal_jobs} j
LEFT JOIN {tripal_bulk_loader} b ON b.job_id=j.job_id
LEFT JOIN (
SELECT nid, count(distinct(group_id)) as num
FROM {tripal_bulk_loader_constants}
GROUP BY nid
) c ON c.nid=b.nid
WHERE j.job_id=%d", $job_id));
if ($job->num_constant_sets) {
$num_constant_sets_loaded = round($job->progress / (100 / $job->num_constant_sets), 4);
// If the next constant set has started loading
if ($job->num_constant_sets != $num_constant_sets_loaded) {
// total lines in input file
$total_lines = trim($job->file);
if ($job->file_has_header) {
$total_lines--;
}
// percent of the current constant set loaded
$percent = round($num_lines / $total_lines * 100, 2);
// percent of the total job = (<# fully loaded constant sets> * 100 )
// + <percent of current constant set>
// / <total number of constant sets>
$total_percent = (($num_constant_sets_loaded * 100) + $percent) / $job->num_constant_sets;
// update the progress of the job
if ($update_progress AND ($percent != 0 OR $percent != 100)) {
tripal_job_set_progress($job_id, round($total_percent, 0));
}
}
}
return (object) array(
'num_lines' => $num_lines,
'total_lines' => $total_lines,
'percent_file' => $percent,
'num_constant_sets_loaded' => $num_constant_sets_loaded,
'total_percent' => $total_percent,
'num_records' => $num_records
);
}