Plack-App-Gearman-Status

 view release on metacpan or  search on metacpan

lib/Plack/App/Gearman/Status.pm  view on Meta::CPAN

				-moz-border-radius: 0px 0px 10px 10px;
			}
			table th {
				border-bottom: 1px solid #DDDDDD;
				background: #FAFAFA;
				padding: 5px;
				font-size: 0.9em;
				color: #555555;
			}
			table td {
				text-align: center;
				padding: 5px;
				font-size: 0.8em;
				color: #444444;
			}
			table tr:hover {
				background: #FBFBFB;
			}
		</style>
	</head>
	<body>
		<h1>Gearman Server Status</h1>
		<% for my $job_server_status (@{$_[0]}) { %>
			<h2>Job server <code><%= $job_server_status->{job_server} %></code></h2>
			<% if ($job_server_status->{error}) { %>
				<p class="error"><%= $job_server_status->{error} %></p>
			<% } else { %>
				<p>Server Version: <%= $job_server_status->{version} %></p>

				<h3>Workers</h3>
				<table class="workers">
					<tr>
						<th>File Descriptor</th>
						<th>IP Address</th>
						<th>Client ID</th>
						<th>Functions</th>
					</tr>
					<% for my $worker (@{$job_server_status->{workers}}) { %>
						<tr>
							<td><%= $worker->file_descriptor() %></td>
							<td><%= $worker->ip_address() %></td>
							<td><%= $worker->client_id() %></td>
							<td><%= join(', ', sort @{$worker->functions()}) %></td>
						</tr>
					<% } %>
				</table>

				<h3>Status</h3>
				<table class="status">
					<tr>
						<th>Function</th>
						<th>Total</th>
						<th>Running</th>
						<th>Available Workers</th>
						<th>Queue</th>
					</tr>
					<% for my $status (@{$job_server_status->{status}}) { %>
						<tr>
							<td><%= $status->name() %></td>
							<td><%= $status->running() %></td>
							<td><%= $status->busy() %></td>
							<td><%= $status->free() %></td>
							<td><%= $status->queue() %></td>
						</tr>
					<% } %>
				</table>
			<% } %>
		<% } %>
	</body>
</html>
EOTPL



sub new {
	my ($class, @arg) = @_;

	my $self = $class->next::method(@arg);

	unless (ref $self->job_servers() eq 'ARRAY') {
		$self->job_servers(['127.0.0.1:4730']);
	}

	$self->connections({});

	$self->template(Text::MicroTemplate->new(
		template   => $template_string,
		tag_start  => '<%',
		tag_end    => '%>',
		line_start => '%',
	)->build());

	return $self;
}



sub parse_job_server_address {
	my ($self, $address) = @_;

	unless (defined $address) {
		croak("Required job server address parameter not passed");
	}

	$address =~ m{^
		# IPv6 address or hostname/IPv4 address
		(?:\[([\d:]+)\]|([\w.-]+))
		# Optional port
		(?::(\d+))?
	$}xms or croak("Unable to parse address '$address'");
	my $host = $1 || $2;
	my $port = $3 || 4730;

	return ($host, $port);
}



sub connection {
	my ($self, $address) = @_;



( run in 2.093 seconds using v1.01-cache-2.11-cpan-364913b4093 )