Updated client to report job status
Using open3 and select, readin raw bytes from the sockets rather than buffered lines to access the handbrake progress information
This commit is contained in:
@@ -121,16 +121,21 @@ my $client = Gearman::Client->new;
|
||||
$client->job_servers($options->{job_servers});
|
||||
|
||||
# Add new ripping task for each job to run
|
||||
my @running_tasks;
|
||||
my @progress;
|
||||
my $taskset = $client->new_task_set;
|
||||
foreach my $job (@jobs) {
|
||||
foreach my $i (0..$#jobs) {
|
||||
my $job = $jobs[$i];
|
||||
$progress[$i] = 0;
|
||||
|
||||
$taskset->add_task('handbrake_rip', freeze($job),
|
||||
{
|
||||
on_status => sub {
|
||||
my $numerator = shift;
|
||||
my $denominator = shift or die;
|
||||
|
||||
$log->notice("Ripping task at ", ($numerator/$denominator), "% complete");
|
||||
|
||||
$progress[$i] = $numerator / $denominator;
|
||||
|
||||
display_progress(@progress);
|
||||
},
|
||||
on_complete => \&on_complete_handler,
|
||||
on_retry => sub {
|
||||
@@ -177,6 +182,15 @@ sub on_complete_handler {
|
||||
$log->notice("Completed rip to $response->{real_output_filename}");
|
||||
}
|
||||
|
||||
sub display_progress {
|
||||
my @progress = @_;
|
||||
|
||||
local $|;
|
||||
$| = 1;
|
||||
|
||||
print "Completion: " . join(' ', map { "$_($progress[$_]%)" } 0..$#progress) . "\r";
|
||||
}
|
||||
|
||||
# Reads configuration options from a config file, expands the internal references, and returns the expanded form.
|
||||
sub parse_config {
|
||||
my $config_file = shift;
|
||||
|
||||
Reference in New Issue
Block a user