NAME
Gearman::Driver::Console - Management console
SYNOPSIS
$ ~/Gearman-Driver$ gearman_driver.pl --console_port 12345 &
[1] 32890
$ ~/Gearman-Driver$ telnet localhost 12345
Trying ::1...
telnet:
connect
to address ::1: Connection refused
Trying fe80::1...
telnet:
connect
to address fe80::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is
'^]'
.
status
GDExamples::Convert::convert_to_jpeg 0 5 0 2010-01-29T20:37:17 1970-01-01T00:00:00
GDExamples::Convert::convert_to_gif 0 5 0 2010-01-29T20:37:12 2010-01-29T20:37:12 some error
.
DESCRIPTION
By default Gearman::Driver provides a management console which can be used with a standard telnet client. It's possible to list all running worker processes as well as changing min/max processes on runtime.
Each successful command ends with a dot. If a command throws an error, a line starting with 'ERR' will be returned.
COMMANDS
All basic commands are implemented in Gearman::Driver::Console::Basic. It's very easy to extend this console with new commands. Every module found in namespace Gearman::Driver::Console::*
will be loaded. Each of those modules has to be implemented as a Moose::Role. You've got access to two attributes/methods there:
driver
- reference to the Gearman::Driver objectserver
- reference to the POE::Component::TCP::Server objectget_job($name)
- returns a Gearman::Driver::Job object
So a new command could look like:
package
Gearman::Driver::Console::List;
use
Moose::Role;
sub
list {
my
(
$self
) =
@_
;
my
@result
= ();
foreach
my
$job
(
$self
->driver->get_jobs ) {
push
@result
,
$job
->name;
}
return
@result
;
}
1;
If you need to throw an error, just die and everything will work as expected (as long as you do not forget the \n
):
package
Gearman::Driver::Console::Broken;
use
Moose::Role;
sub
broken {
my
(
$self
) =
@_
;
die
"ERR this is a broken command\n"
;
}
sub
get_max_processes {
my
(
$self
,
$job_name
) =
@_
;
my
$job
=
$self
->get_job(
$job_name
);
# this automatically dies if job is not found
return
$job
->max_processes;
}
1;
Yes, that's all...
$ ~/Gearman-Driver$ telnet localhost 47300
Trying ::1...
telnet:
connect
to address ::1: Connection refused
Trying fe80::1...
telnet:
connect
to address fe80::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is
'^]'
.
list
GDExamples::Convert::convert_to_jpeg
GDExamples::Convert::convert_to_gif
.
broken
ERR this is a broken command
get_max_processes asdf
ERR invalid_job_name: asdf
get_max_processes GDExamples::Convert::convert_to_jpeg
6
.
AUTHOR
See Gearman::Driver.
COPYRIGHT AND LICENSE
See Gearman::Driver.