Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 52 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. package Plack::Server::GearmanWorker;
  2. use strict;
  3. use warnings;
  4. use Gearman::Worker;
  5.  
  6. sub new {
  7.     my($class, %args) = @_;
  8.     bless {%args}, $class;
  9. }
  10.  
  11. sub run {
  12.     my($self, $app) = @_;
  13.  
  14.     my $worker = Gearman::Worker->new;
  15.     $worker->job_servers(@{$self->{host} || [ '127.0.0.1' ]});
  16.     $worker->register_function($self->{func_name} || 'psgi_handler' => sub {
  17.         my $env = Storable::thaw(shift->arg);
  18.         my $res = do {
  19.             local $env->{'psgi.errors'} = \*STDERR;
  20.             Plack::Util::run_app $app, $env;
  21.         };
  22.  
  23.         my $body;
  24.         Plack::Util::foreach($res->[2], sub { $body .= shift });
  25.         $res->[2] = [ $body ];
  26.  
  27.         Storable::freeze($res);
  28.     });
  29.  
  30.     warn "Accepting worker jobs at Gearman job server: ", join(", ", @{$worker->job_servers}), "\n";
  31.     $worker->work while 1;
  32. }
  33.  
  34. 1;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top