Add client process part
This commit is contained in:
parent
36303bf472
commit
068e23a4ce
@ -41,8 +41,8 @@ sub do_work ($$$@)
|
||||
my $given_args = shift;
|
||||
my $priority = shift;
|
||||
|
||||
log(DEBUG, "Starting job");
|
||||
log(TRACE, $_[0]{argref});
|
||||
log DEBUG, "Starting job";
|
||||
log TRACE, $_[0]{argref};
|
||||
|
||||
my $old = 0;
|
||||
# Check the load isn't to high for this process
|
||||
@ -79,11 +79,88 @@ sub register ($$;$$)
|
||||
$worker->job_servers('gearmand:4730');
|
||||
$worker->register_function($funcname => sub { return do_work($subref, $given_arg, $priority, @_); });
|
||||
|
||||
say "$funcname registered";
|
||||
log DEBUG, "$funcname registered";
|
||||
|
||||
$worker->work while 1;
|
||||
}
|
||||
|
||||
package Process::Client;
|
||||
|
||||
use v5.10.1;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
use Gearman::Client;
|
||||
use XML::LibXML;
|
||||
|
||||
use ACU::Log;
|
||||
|
||||
sub build_task_xml($)
|
||||
{
|
||||
my $params = shift;
|
||||
|
||||
my $doc = XML::LibXML::Document->new('1.0');
|
||||
my $root = $doc->createElement("sync_ssh_keys");
|
||||
$doc->setDocumentElement( $root );
|
||||
|
||||
log TRACE, $params;
|
||||
|
||||
for my $key (keys %{ $params })
|
||||
{
|
||||
my $param = $doc->createElement("param");
|
||||
if ($key !~ /^__[0-9]+$/) {
|
||||
$param->addChild( $doc->createAttribute("name", $key) );
|
||||
}
|
||||
$param->appendText($params->{$key});
|
||||
$root->appendChild($param);
|
||||
}
|
||||
|
||||
my $ret = $doc->toString();
|
||||
log TRACE, $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub launch ($$;$)
|
||||
{
|
||||
my $funcname = shift;
|
||||
|
||||
my $client = Gearman::Client->new;
|
||||
$client->job_servers('gearmand:4730');
|
||||
|
||||
log DEBUG, "Launching $funcname...";
|
||||
|
||||
my $xml = build_task_xml(shift);
|
||||
|
||||
if (shift) {
|
||||
return $client->dispatch_background($funcname, $xml);
|
||||
}
|
||||
else {
|
||||
return $client->do_task($funcname, $xml);
|
||||
}
|
||||
}
|
||||
|
||||
sub paralaunch ($$)
|
||||
{
|
||||
my $funcsname = shift;
|
||||
log TRACE, $funcsname;
|
||||
|
||||
# Build XML
|
||||
my $xml = build_task_xml(shift);
|
||||
|
||||
my $client = Gearman::Client->new;
|
||||
$client->job_servers('gearmand:4730');
|
||||
|
||||
my $taskset = $client->new_task_set;
|
||||
for my $task (@{ $funcsname })
|
||||
{
|
||||
log DEBUG, "Launching $task...";
|
||||
|
||||
$taskset->add_task($task => $xml);
|
||||
}
|
||||
$taskset->wait;
|
||||
|
||||
return "Ok";
|
||||
}
|
||||
|
||||
package SubtreeItem;
|
||||
|
||||
|
Reference in New Issue
Block a user