Daemon/Buildd.pm

filter: Statementstmt 100% 15 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 100% 20 / 20 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« BuildCommand/Submitter.pm ↑ Summary Daemon/Incoming.pm »
1 package PkgForge::Daemon::Buildd; # -*-perl-*-
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # $Id: Buildd.pm.in 17473 2011-06-01 13:07:47Z squinney@INF.ED.AC.UK $
6 # $Source:$
7 # $Revision: 17473 $
8 # $HeadURL: https://svn.lcfg.org/svn/source/tags/PkgForge-Server/PkgForge_Server_1_1_10/lib/PkgForge/Daemon/Buildd.pm.in $
9 # $Date: 2011-06-01 14:07:47 +0100 (Wed, 01 Jun 2011) $
10  
11 our $VERSION = '1.1.10';
12  
13 my $PLEASE_STOP = 0;
14  
15 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use MooseX::Types::Moose qw(Int);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 extends 'PkgForge::Daemon', 'PkgForge::Handler::Buildd';
19  
20 has 'poll' => (
21 is => 'ro',
22 isa => Int,
23 default => 60,
24 required => 1,
25 documentation => 'Interval (in seconds) to wait between queue runs',
26 );
27  
28 # Different pidfile for each individual buildd
29  
30 override 'init_pidfile' => sub {
31 my ($self) = @_;
32  
33 my $file = $self->progname . '-' . $self->name . '.pid';
34 my $path = File::Spec->catfile( $self->pidfile_dir, $file );
35  
36 return $path;
37 };
38  
39 override 'status_message' => sub {
40 my ( $self, $pid ) = @_;
41  
42 my $name = $self->name;
43 if ($pid) {
44 print "Build daemon '$name' is running with PID $pid\n";
45 } else {
46 print "Build daemon '$name' is not running\n";
47 }
48  
49 return;
50 };
51  
52 override 'shutdown' => sub {
53 my ($self) = @_;
54  
55 $self->logger->notice('Handling shutdown request');
56  
57 $PLEASE_STOP = 1;
58  
59 return;
60 };
61  
62 after 'start' => sub {
63 my ($self) = @_;
64  
65 my $name = $self->name;
66  
67 $self->logger->notice("Starting build daemon '$name'");
68  
69 $self->preflight();
70  
71 while ( !$PLEASE_STOP ) {
72 my $task = $self->next_task;
73 while ( !$PLEASE_STOP && !defined $task ) {
74 sleep $self->poll;
75 $task = $self->next_task;
76 }
77  
78 if ( !$PLEASE_STOP ) {
79 my $uuid = $task->job->uuid;
80 $self->logger->notice("Starting task $uuid on " . $self->name);
81 $self->execute($task);
82 $self->logger->notice("Finished task $uuid on " . $self->name);
83 }
84  
85 # Try to leave the registry in a nice state if we didn't complete
86 # the job. This way it will be attempted again later.
87  
88 $self->reset_unfinished_tasks();
89  
90 }
91  
92 $self->logger->notice("Stopping build daemon '$name'");
93  
94 exit 0;
95 };
96  
97 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 __PACKAGE__->meta->make_immutable;
99  
100 1;
101 __END__
« BuildCommand/Submitter.pm ↑ Summary Daemon/Incoming.pm »