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

fix funcname regexp. it may include a prefix_separator tab. #46

Closed
wants to merge 1 commit into from

Conversation

bokutin
Copy link

@bokutin bokutin commented Jul 25, 2020

Hello,

If prefix is used as follows, get_job_server_status cannot get information.

my $client = Gearman::Client->new( job_servers => ['127.0.0.1:4730'], prefix => 'myapp' ) 
$client->get_job_server_status;

The function name can contain anything. For example

gearman -w -f "prefix1| \t\n^Mfunc1日本語UTF-8"

First of all, I hope that it will work even if the default value tab of prefix_separator is included.

Thanks,

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 86.515% when pulling 034cbf8 on bokutin:fix_funcname_regexp into 6ad2eab on p-alik:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 86.515% when pulling 034cbf8 on bokutin:fix_funcname_regexp into 6ad2eab on p-alik:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 86.515% when pulling 034cbf8 on bokutin:fix_funcname_regexp into 6ad2eab on p-alik:master.

@p-alik
Copy link
Owner

p-alik commented Jul 25, 2020

Thank you for catching that, @bokutin!
I'll review it on Monday.

@bokutin
Copy link
Author

bokutin commented Jul 26, 2020

Thank you for having interest!

I did a little more research.

#!/usr/local/bin/perl

use rlib;
use Modern::Perl;
use Data::Dumper;
use Gearman::Client;
use Gearman::Worker;
use JSON::MaybeXS;
use URI::Escape;

my $bin = "\xFF"; # binary, not ascii

my $worker = Gearman::Worker->new;
$worker->job_servers( '127.0.0.1' );

$worker->register_function( "func1\t<-tab",               sub {}) or die;
$worker->register_function( "func1\x0a<-LF",              sub {}) or die;
$worker->register_function( "func1\x0d\x0a<-CR_LF",       sub {}) or die;
$worker->register_function( "func1 <-space",              sub {}) or die;
$worker->register_function( "func1$bin<-binary_or_empty", sub {}) or die;
$worker->register_function( "func1<-binary_or_empty",     sub {}) or die;

# Including this line will break the parser below.
# Perhaps it may not be possible to create a parser with current specification
# of "status" of Gearman Administrative Protocol.
# $worker->register_function( "func2\t0\t0\t0\nfunc3",    sub {}) or die;

my $client = Gearman::Client->new;
$client->job_servers( '127.0.0.1' );

my $text = "";
$client->_job_server_status_command( # same as "echo status | nc 127.0.0.1 4730"
    "status\n",
    sub {
        my ($js, $line) = @_;
        $text .= $line."\n";
    },
);

my @func;
push @func, { job => $1, queued => $2, running => $3, capable => $4 }
    while $text =~ m{^(.*?)\t(\d+)\t(\d+)\t(\d+)$}msg;
$_->{job_hex} = uri_escape $_->{job} for @func;
@func = sort { $a->{job_hex} cmp $b->{job_hex} } @func;

say JSON::MaybeXS->new->canonical->pretty->encode( \@func );

__END__

% ./test.pl | cat -v
[
   {
      "capable" : "1",
      "job" : "func1\t<-tab",
      "job_hex" : "func1%09%3C-tab",
      "queued" : "0",
      "running" : "0"
   },
   {
      "capable" : "1",
      "job" : "func1\n<-LF",
      "job_hex" : "func1%0A%3C-LF",
      "queued" : "0",
      "running" : "0"
   },
   {
      "capable" : "1",
      "job" : "func1\r\n<-CR_LF",
      "job_hex" : "func1%0D%0A%3C-CR_LF",
      "queued" : "0",
      "running" : "0"
   },
   {
      "capable" : "1",
      "job" : "func1 <-space",
      "job_hex" : "func1%20%3C-space",
      "queued" : "0",
      "running" : "0"
   },
   {
      "capable" : "1",
      "job" : "func1<-binary_or_empty",
      "job_hex" : "func1%3C-binary_or_empty",
      "queued" : "0",
      "running" : "0"
   },
   {
      "capable" : "1",
      "job" : "func1M-^?<-binary_or_empty",
      "job_hex" : "func1%FF%3C-binary_or_empty",
      "queued" : "0",
      "running" : "0"
   }
]

It seems that any value can be used as the function name.

According to JOB_ASSIGN of http://gearman.org/protocol/ , it seems to be a constraint only for "NULL byte terminated function name".

I tried the following two as if they were dependent on the server implementation, but the behavior was the same.
https://www.freshports.org/devel/gearmand
https://www.freshports.org/devel/p5-Gearman-Server

I'm sorry that I found it troublesome.

@bokutin
Copy link
Author

bokutin commented Jul 27, 2020

Thank you for your help with gearman/gearmand as well.

As for the function name of gearman, it is possible to include anything other than \0, so I understood that it should be used so that the user does not break it.

You can simply close this Issue.

I'm sorry to bother you.

@bokutin
Copy link
Author

bokutin commented Jul 27, 2020

I also considered such an option.
bokutin@2a72f23

@p-alik p-alik closed this Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants