--- /dev/null
+<!doctype html>
+<html xmlns:ng="http://angularjs.org">
+ <script src="http://code.angularjs.org/angular-0.9.12.min.js" ng:autobind></script>
+ <body>
+ <script>
+ function GearmanCntl($xhr) {
+ var self = this;
+
+ this.status_update = function() {
+ $xhr('JSON', '/_g/status?callback=JSON_CALLBACK', function(code,response) {
+ self.g = response;
+ });
+ }
+ this.status_update();
+
+ this.fetch = function() {
+ self.clear();
+ self.url = '/g/' + self.function + '/' + self.args + '?callback=JSON_CALLBACK';
+ $xhr('JSON', self.url, function(code, response) {
+ self.code = code;
+ self.response = response;
+ });
+ };
+
+ this.clear = function() {
+ self.code = null;
+ self.response = null;
+ };
+ }
+ GearmanCntl.$inject = ['$xhr'];
+ </script>
+ <div ng:controller="GearmanCntl">
+ <select name="function">
+ <option ng:repeat="f in g.status" ng:show="f.available" value="{{f.function}}">{{f.function}}</option>
+ <input type="text" name="args" value="127.0.0.1" size="40"/>
+ <button ng:click="fetch()">fetch</button>
+ <button ng:click="clear()">clear</button>
+
+ <pre>
+url={{url}}
+code={{code}}
+response={{response}}
+ </pre>
+
+<table>
+<tr><th>function</th><th>total</th><th>running</th><th>available</th></tr>
+<tr ng:repeat="f in g.status">
+<td>{{f.function}}</td>
+<td>{{f.total}}</td>
+<td>{{f.running}}</td>
+<td>{{f.available}}</td>
+</tr>
+</table>
+<button ng:click="status_update()">update</button>
+
+ </div>
+ </body>
+</html>
die "no result for ", $self->param('call'), ' args: ', $self->param('args') unless defined $ret;
_render_jsonp( $self, $ret );
};
+
+get '/_g/status' => sub {
+ my $self = shift;
+
+ my $ret = $gearman->req( 'TEXT' => 'status' );
+ warn "# status:\n$ret";
+
+ my @c = qw(function total running available);
+
+ my $status;
+ foreach my $l ( split(/\n/,$ret) ) {
+ my @v = split(/\t/, $l);
+ my $h;
+ $h->{$c[$_]} = $v[$_] foreach 0 .. $#v;
+ push @$status, $h;
+ }
+ warn "## ", dump $status;
+ _render_jsonp( $self, Mojo::JSON->new->encode({ status => $status }) );
+};
+
app->start;
__DATA__
% title 'Gearman demo';
Welcome to Mojolicious Gearman integration demo!
+<p>
+
+<%= link_to 'Gearman web interface' => 'gearman.html' %>
+
+<p>
+
+Low-level API tests:
+
<%= link_to 'HTTP ping' => 'ping_http' %>
<%= link_to 'Gearman ping' => 'ping_g' %>