Gearman-Driver

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    *   default: "gearman_driver.log"

  loglayout
    See also Log::Log4perl.

    *   isa: "Str"

    *   default: "[%d] %p %m%n"

  loglevel
    See also Log::Log4perl.

    *   isa: "Str"

    *   default: "INFO"

  unknown_job_callback
    Whenever Gearman::Driver::Observer sees a job that isnt handled it will
    call this CodeRef, passing following arguments:

    *   $driver

    *   $status

        my $driver = Gearman::Driver->new(
            namespaces           => [qw(My::Workers)],
            unknown_job_callback => sub {
                my ( $driver, $status ) = @_;
                # notify nagios here for example
            }
        );

    $status might look like:

        $VAR1 = {
            'busy'    => 0,
            'free'    => 0,
            'name'    => 'GDExamples::Convert::unknown_job',
            'queue'   => 6,
            'running' => 0
        };

  worker_options
    You can pass runtime options to the worker module, these will merged
    with 'GLOBAL' and pass to the worker constructor. ( worker options
    override globals )

    *   default: "{}"

    *   isa: "HashRef"

    Example:

        my $driver = Gearman::Driver->new(
            namespaces     => [qw(My::Workers)],
            worker_options => {
                'GLOBAL' => {
                    'config' => $config,
                },
                'My::Workers::MysqlPing' => {
                    'dsn' => 'DBI:mysql:database=test;host=localhost;mysql_auto_reconnect=1;mysql_enable_utf8=1;mysql_server_prepare=1;',
                },
                'My::Workers::ImageThumbnail' => {
                    'default_format' => 'jpeg',
                    'default_size => ' 133 x 100 ',
                }
            }
        );

    You should define these in a runtime config (See also "configfile"),
    might be:

        ---
        worker_options:
            'My::App::Worker::MysqlPing':
                'dsn': 'DBI:mysql:database=test;host=localhost;mysql_auto_reconnect=1;mysql_enable_utf8=1;mysql_server_prepare=1;'
                'user': 'root'
                'password:': ''
            'My::App::Worker::ImageThumbnail':
                'default_format': 'jpeg'
                'default_size': '133x100'

  Job runtime attributes
    You can override a job attribute by its name here. This help to tuning
    job some runtime-related options (like max_processes, min_processes)
    handy. You just change the options in a config file, no need to modify
    the worker code anymore.

    Currently only 'max_processes', 'min_processes' make sense. The hash key
    is "worker_module::job_key", job_key is ProcessGroup attribute or job
    method name.

        #in your config file: /etc/gearman-driver.yml (YAML)
        ---
        job_runtime_attributes:
            'My::App::Worker::job1':
                max_processes: 25
                min_processes: 2
            #job has a ProcessGroup attribute named 'group1'
            'My::App::Worker::group1':
                max_processes: 10
                min_processes: 2
        #then run as:
        gearman_driver.pl --configfile /etc/gearman_driver.yml

  configfile
    Runtime config file path, You can provide a default configfile pathname
    like so:

        has +configfile ( default => '/etc/gearman-driver.yaml' );

    You can pass an array of filenames if you want, like:

        has +configfile ( default => sub { [ '/etc/gearman-driver.yaml','/opt/my-app/etc/config.yml' ] });

  daemonize
    Detach self and run as a daemon.

INTERNAL ATTRIBUTES
    This might be interesting for subclassing Gearman::Driver.

  jobs
    Stores all Gearman::Driver::Job instances. There are also two methods:

    *   get_job

    *   has_job

    Example:

        {
            'My::Workers::ONE::scale_image'       => bless( {...}, 'Gearman::Driver::Job' ),
            'My::Workers::ONE::do_something_else' => bless( {...}, 'Gearman::Driver::Job' ),
            'My::Workers::TWO::scale_image'       => bless( {...}, 'Gearman::Driver::Job' ),
        }



( run in 1.230 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )