Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DATA packets #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Gearman/Objects.pm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use fields (
'on_exception',
'on_retry',
'on_status',
'on_data',
'on_post_hooks', # used internally, when other hooks are done running, prior to cleanup
'retry_count',
'timeout',
Expand Down
10 changes: 9 additions & 1 deletion lib/Gearman/Task.pm
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,19 @@ sub complete {
sub status {
my Gearman::Task $task = shift;
return if $task->{is_finished};
return unless $task->{on_status};

my ($nu, $de) = @_;
$task->{on_status}->($nu, $de);
}

sub data {
my Gearman::Task $task = shift;
return if $task->{is_finished};
my $result_ref = shift;

$task->{on_data}->($result_ref) if $task->{on_data};
}

# getter/setter for the fully-qualified handle of form "IP:port//shandle" where
# shandle is an opaque handle specific to the job server running on IP:port
sub handle {
Expand Down
18 changes: 18 additions & 0 deletions lib/Gearman/Taskset.pm
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ sub wait {
# -- on_complete
# -- on_fail
# -- on_status
# -- on_data
# -- retry_count
# -- fail_after_idle
# -- high_priority
Expand Down Expand Up @@ -322,6 +323,23 @@ sub _process_packet {
return 1;
}

if ($res->{type} eq "work_data") {
${ $res->{'blobref'} } =~ s/^(.+?)\0//
or die "Bogus work_data from server";
my $shandle = $1;

my $task_list = $ts->{waiting}{$shandle} or
die "Uhhhh: got work_data for unknown handle: $shandle\n";

my Gearman::Task $task = $task_list->[0] or
die "Uhhhh: task_list is empty on work_data for handle $shandle\n";

$task->data($res->{'blobref'});

return 1;
}


if ($res->{type} eq "work_exception") {
${ $res->{'blobref'} } =~ s/^(.+?)\0//
or die "Bogus work_exception from server";
Expand Down
1 change: 1 addition & 0 deletions lib/Gearman/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ our %cmd = (
# to one jobserver, so no polls/grabs will take place, and server is free
# to push "job_assign" packets back down.
24 => [ 'I', "all_yours" ], # W->J ---
28 => [ 'IO', "work_data"], # W->J/C: HANDLE[0]RES
);

our %num; # name -> num
Expand Down