Bugzilla::JobQueue::Runner code style

hinted-selects
Vitaliy Filippov 2014-07-23 19:20:45 +04:00
parent 776ec7b928
commit be8da34422
1 changed files with 55 additions and 34 deletions

View File

@ -1,5 +1,3 @@
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
@ -16,7 +14,7 @@
# Portions created by the Initial Developer are Copyright (C) 2008
# Mozilla Corporation. All Rights Reserved.
#
# Contributor(s):
# Contributor(s):
# Mark Smith <mark@mozilla.com>
# Max Kanat-Alexander <mkanat@bugzilla.org>
@ -39,6 +37,7 @@ BEGIN { eval "use base qw(Daemon::Generic)"; }
our $VERSION = BUGZILLA_VERSION;
# FIXME: Support Debian :)
# Info we need to install/uninstall the daemon on RHEL/Fedora.
our $chkconfig = "/sbin/chkconfig";
our $initd = "/etc/init.d";
@ -48,28 +47,32 @@ our $initscript = "bugzilla-queue";
# things from gd_preconfig, but in fact it does not. The
# only thing it uses from gd_preconfig is the "pidfile"
# config parameter.
sub gd_preconfig {
sub gd_preconfig
{
my $self = shift;
my $pidfile = $self->{gd_args}{pidfile};
if (!$pidfile) {
$pidfile = bz_locations()->{datadir} . '/' . $self->{gd_progname}
. ".pid";
if (!$pidfile)
{
$pidfile = bz_locations()->{datadir} . '/' . $self->{gd_progname} . ".pid";
}
return (pidfile => $pidfile);
}
# All config other than the pidfile has to be done in gd_getopt
# in order for it to be set up early enough.
sub gd_getopt {
sub gd_getopt
{
my $self = shift;
$self->SUPER::gd_getopt();
if ($self->{gd_args}{progname}) {
if ($self->{gd_args}{progname})
{
$self->{gd_progname} = $self->{gd_args}{progname};
}
else {
else
{
$self->{gd_progname} = basename($0);
}
@ -79,14 +82,16 @@ sub gd_getopt {
$0 = $self->{gd_progname};
}
sub gd_postconfig {
sub gd_postconfig
{
my $self = shift;
# See the hack above in gd_getopt. This just reverses it
# in case anything else needs the accurate $0.
$0 = delete $self->{_original_zero};
}
sub gd_more_opt {
sub gd_more_opt
{
my $self = shift;
return (
'pidfile=s' => \$self->{gd_args}{pidfile},
@ -94,12 +99,14 @@ sub gd_more_opt {
);
}
sub gd_usage {
sub gd_usage
{
pod2usage({ -verbose => 0, -exitval => 'NOEXIT' });
return 0
}
sub gd_can_install {
sub gd_can_install
{
my $self = shift;
my $source_file = "contrib/$initscript";
@ -107,19 +114,24 @@ sub gd_can_install {
my $sysconfig = '/etc/sysconfig';
my $config_file = "$sysconfig/$initscript";
if (!-x $chkconfig or !-d $initd) {
if (!-x $chkconfig or !-d $initd)
{
return $self->SUPER::gd_can_install(@_);
}
return sub {
if (!-w $initd) {
return sub
{
if (!-w $initd)
{
print "You must run the 'install' command as root.\n";
return;
}
if (-e $dest_file) {
if (-e $dest_file)
{
print "$initscript already in $initd.\n";
}
else {
else
{
copy($source_file, $dest_file)
or die "Could not copy $source_file to $dest_file: $!";
chmod(0755, $dest_file)
@ -127,11 +139,12 @@ sub gd_can_install {
}
system($chkconfig, '--add', $initscript);
print "$initscript installed.",
" To start the daemon, do \"$dest_file start\" as root.\n";
print "$initscript installed. To start the daemon, do \"$dest_file start\" as root.\n";
if (-d $sysconfig and -w $sysconfig) {
if (-e $config_file) {
if (-d $sysconfig and -w $sysconfig)
{
if (-e $config_file)
{
print "$config_file already exists.\n";
return;
}
@ -148,50 +161,58 @@ USER=$owner
END
close($config_fh);
}
else {
else
{
print "Please edit $dest_file to configure the daemon.\n";
}
}
}
sub gd_can_uninstall {
sub gd_can_uninstall
{
my $self = shift;
if (-x $chkconfig and -d $initd) {
return sub {
if (!-e "$initd/$initscript") {
if (-x $chkconfig and -d $initd)
{
return sub
{
if (!-e "$initd/$initscript")
{
print "$initscript not installed.\n";
return;
}
system($chkconfig, '--del', $initscript);
print "$initscript disabled.",
" To stop it, run: $initd/$initscript stop\n";
print "$initscript disabled. To stop it, run: $initd/$initscript stop\n";
}
}
return $self->SUPER::gd_can_install(@_);
}
sub gd_check {
sub gd_check
{
my $self = shift;
# Get a count of all the jobs currently in the queue.
my $jq = Bugzilla->job_queue();
my @dbs = $jq->bz_databases();
my $count = 0;
foreach my $driver (@dbs) {
foreach my $driver (@dbs)
{
$count += $driver->select_one('SELECT COUNT(*) FROM ts_job', []);
}
print get_text('job_queue_depth', { count => $count }) . "\n";
}
sub gd_setup_signals {
sub gd_setup_signals
{
my $self = shift;
$self->SUPER::gd_setup_signals();
$SIG{TERM} = sub { $self->gd_quit_event(); }
}
sub gd_run {
sub gd_run
{
my $self = shift;
my $jq = Bugzilla->job_queue();