Commit 09d0a233 authored by sikeda's avatar sikeda
Browse files

[-dev] Introducing {generation} attribute of Sympa::Process object instead of...

[-dev] Introducing {generation} attribute of Sympa::Process object instead of $daemon_usage global variable.


git-svn-id: https://subversion.renater.fr/sympa/branches/sympa-6.2-branch@12513 05aa8bb8-cd2b-0410-b1d7-8918dfa770ce
parent 11e55444
......@@ -45,7 +45,10 @@ my $log = Sympa::Log->instance;
sub _new_instance {
my $class = shift;
bless {children => {}} => $class;
bless {
children => {},
generation => 0,
} => $class;
}
sub init {
......@@ -69,6 +72,7 @@ sub fork {
$self->{children}->{$pid} = $tag;
} else {
$self->{children} = {};
$self->{generation}++;
}
$pid;
}
......@@ -529,6 +533,11 @@ L<Sympa::Process> instance may have following attributes:
Hashref with child PIDs forked by fork() method as keys.
=item {generation}
Generation of process.
If fork() method succeeds, it will be increased by child process.
=back
=head1 HISTORY
......
......@@ -52,8 +52,6 @@ my $process = Sympa::Process->instance;
$process->init(pidname => 'bulk');
my $date_of_last_activity = time();
local $main::daemon_usage =
'DAEMON_MASTER'; ## Default is to launch bulk as master daemon.
## Check options
## --debug : sets the debug mode
......@@ -119,9 +117,6 @@ if ($main::options{'log_level'}) {
);
}
## Set the process as main bulk daemon by default.
my $is_main_bulk = 0;
## Put ourselves in background if not in debug mode.
unless ($main::options{'debug'} || $main::options{'foreground'}) {
open(STDERR, ">> /dev/null");
......@@ -203,11 +198,11 @@ while (!$end) {
unless ($main::options{'foreground'}) {
# Create child bulks if too much packets are waiting to be sent in
# the bulk_mailer table.
# Only the main bulk process (DAEMON_MASTER) can create child
# Only the main bulk process ({generation} is 0) can create child
# processes.
# Check if we need to run new child processes every
# 'bulk_wait_to_fork' (sympa.conf parameter) seconds.
if ( $main::daemon_usage eq 'DAEMON_MASTER'
if (0 == $process->{generation}
and $timeout < time - $last_check_date) {
# Clean up PID file (in case some child bulks would have died)
$process->reap_child(children => \%created_children, file => 1);
......@@ -249,7 +244,6 @@ while (!$end) {
close STDERR;
$process->direct_stderr_to_file;
$date_of_last_activity = time();
$main::daemon_usage = 'DAEMON_SLAVE'; # child bulk
$log->openlog($Conf::Conf{'syslog'},
$Conf::Conf{'log_socket_type'});
$log->syslog('info',
......@@ -269,7 +263,7 @@ while (!$end) {
}
## If a child bulk process is running for long enough, stop it (if the
## number of remaining packets to send is reasonnable).
if ( $main::daemon_usage eq 'DAEMON_SLAVE'
if ( 0 < $process->{generation}
and time() - $date_of_last_activity > $Conf::Conf{'bulk_lazytime'}
and !(my $r_packets = $bulk->too_much_remaining_packets())) {
$log->syslog('info',
......
......@@ -62,9 +62,6 @@ my $digestsleep = 5;
## Init random engine
srand(time());
# Default is to launch process as master daemon.
my $daemon_usage = 'DAEMON_MASTER';
# Check options.
my %options;
unless (
......@@ -154,7 +151,7 @@ unless ($main::options{foreground}) {
# Start multiple processes if required.
unless ($main::options{'foreground'}) {
if ($daemon_usage eq 'DAEMON_MASTER'
if (0 == $process->{generation}
and ($Conf::Conf{'incoming_max_count'} || 0) > 1) {
# Disconnect from database before fork to prevent DB handles
# to be shared by different processes. Sharing database
......@@ -162,7 +159,7 @@ unless ($main::options{'foreground'}) {
Sympa::DatabaseManager->disconnect;
for my $process_count (2 .. $Conf::Conf{'incoming_max_count'}) {
my $child_pid = fork;
my $child_pid = $process->fork;
if ($child_pid) {
$log->syslog('info', 'Starting child daemon, PID %s',
$child_pid);
......@@ -177,7 +174,6 @@ unless ($main::options{'foreground'}) {
# We're in a child process
close STDERR;
$process->direct_stderr_to_file;
$daemon_usage = 'DAEMON_SLAVE'; # child
$log->openlog($Conf::Conf{'syslog'},
$Conf::Conf{'log_socket_type'});
$log->syslog('info', 'Slave daemon started with PID %s',
......@@ -267,9 +263,9 @@ while ($signal ne 'term') {
# Process grouped notifications
Sympa::Alarm->instance->flush;
# process digest only in distribution mode.
# Process digest only in master process ({generation} is 0).
# Scan queuedigest.
if ( $daemon_usage eq 'DAEMON_MASTER'
if (0 == $process->{generation}
and $index_queuedigest++ >= $digestsleep) {
$index_queuedigest = 0;
Sympa::Spindle::SendDigest->new->spin;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment