Updated callbacks

Using anonymous subs for the simple callbacks instead of named subs
Using reference rather than direct hash access to construct the response
This commit is contained in:
Ben Roberts
2010-02-20 01:32:39 +00:00
parent f71987cbb6
commit e9bfe27782
2 changed files with 63 additions and 39 deletions

View File

@@ -121,12 +121,25 @@ my $client = Gearman::Client->new;
$client->job_servers($options->{job_servers});
# Add new ripping task for each job to run
my @running_tasks;
my $taskset = $client->new_task_set;
foreach my $job (@jobs) {
$taskset->add_task("handbrake_rip", freeze($job),
$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");
},
on_complete => \&on_complete_handler,
on_fail => \&on_fail_handler,
on_retry => sub {
my $attempt = shift or die;
$log->warning("Retrying rip");
},
on_fail => sub {
$log->warning("Rip failed");
},
}
);
}
@@ -164,10 +177,6 @@ sub on_complete_handler {
$log->notice("Completed rip to $response->{real_output_filename}");
}
sub on_fail_handler {
$log->error("Failed to distribute job");
}
# Reads configuration options from a config file, expands the internal references, and returns the expanded form.
sub parse_config {
my $config_file = shift;