Archived
1
0

Can send files with Process::Client

This commit is contained in:
Mercier Pierre-Olivier 2013-09-12 12:53:59 +02:00
parent d4cc9547db
commit 6ca9007fde
2 changed files with 26 additions and 6 deletions

View File

@ -79,6 +79,10 @@ sub register ($$;$$)
$worker->job_servers('gearmand:4730');
$worker->register_function($funcname => sub { return do_work($subref, $given_arg, $priority, @_); });
# Disable exit on warning or error
$ACU::Log::fatal_warn = 0;
$ACU::Log::fatal_error = 0;
log DEBUG, "$funcname registered";
$worker->work while 1;
@ -91,13 +95,15 @@ use strict;
use warnings;
use Carp;
use Gearman::Client;
use MIME::Base64;
use XML::LibXML;
use ACU::Log;
sub build_task_xml($)
sub build_task_xml($;$)
{
my $params = shift;
my $files = shift;
my $doc = XML::LibXML::Document->new('1.0');
my $root = $doc->createElement("sync_ssh_keys");
@ -115,12 +121,26 @@ sub build_task_xml($)
$root->appendChild($param);
}
if ($files)
{
log TRACE, $files;
for my $key (keys %{ $files })
{
my $file = $doc->createElement("file");
$file->addChild( $doc->createAttribute("name", $key) );
$file->addChild( $doc->createAttribute("encoding", "base64") );
$file->appendText(encode_base64($files->{$key}));
$root->appendChild($file);
}
}
my $ret = $doc->toString();
log TRACE, $ret;
return $ret;
}
sub launch ($$;$)
sub launch ($$;$$)
{
my $funcname = shift;
@ -129,7 +149,7 @@ sub launch ($$;$)
log DEBUG, "Launching $funcname...";
my $xml = build_task_xml(shift);
my $xml = build_task_xml(shift, shift);
if (shift) {
return $client->dispatch_background($funcname, $xml);
@ -139,13 +159,13 @@ sub launch ($$;$)
}
}
sub paralaunch ($$)
sub paralaunch ($$;$)
{
my $funcsname = shift;
log TRACE, $funcsname;
# Build XML
my $xml = build_task_xml(shift);
my $xml = build_task_xml(shift, shift);
my $client = Gearman::Client->new;
$client->job_servers('gearmand:4730');

View File

@ -285,7 +285,7 @@ sub process_user
}
alert_mail($ldap, $args->{param}{"uid"}, $dn, $action, @ssh_name);
Process::Client::launch("sync_ssh_keys", { "action" => "update", "__0" => $args->{param}{"uid"} }, 1);
Process::Client::launch("sync_ssh_keys", { "action" => "update", "__0" => $args->{param}{"uid"} }, undef, 1);
}
$ldap->unbind or warn "couldn't disconnect correctly";