]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1441181 - Step 8 - Add jobqueue command to entrypoint
authorDylan William Hardison <dylan@hardison.net>
Tue, 13 Mar 2018 20:40:59 +0000 (16:40 -0400)
committerGitHub <noreply@github.com>
Tue, 13 Mar 2018 20:40:59 +0000 (16:40 -0400)
Bugzilla/DaemonControl.pm
docker-compose.yml
scripts/entrypoint.pl

index 510886dbaf16b47e71110a377c489b217d0c65f7..6586cc01b60fc0765c0b3d71a11c00ce015f66ae 100644 (file)
@@ -28,7 +28,8 @@ use POSIX qw(setsid WEXITSTATUS);
 use base qw(Exporter);
 
 our @EXPORT_OK = qw(
-    run_httpd run_cereal run_cereal_and_httpd
+    run_httpd run_cereal run_jobqueue
+    run_cereal_and_httpd run_cereal_and_jobqueue
     catch_signal on_finish on_exception
     assert_httpd assert_database assert_selenium
 );
@@ -39,10 +40,12 @@ our %EXPORT_TAGS = (
     utils => [qw(catch_signal on_exception on_finish)],
 );
 
-use constant CEREAL_BIN    => realpath(catfile( bz_locations->{cgi_path}, 'scripts', 'cereal.pl'));
-
-use constant HTTPD_BIN     => '/usr/sbin/httpd';
-use constant HTTPD_CONFIG  => realpath(catfile( bz_locations->{confdir}, 'httpd.conf' ));
+use constant {
+    JOBQUEUE_BIN => realpath( catfile( bz_locations->{cgi_path}, 'jobqueue.pl' ) ),
+    CEREAL_BIN   => realpath( catfile( bz_locations->{cgi_path}, 'scripts', 'cereal.pl' ) ),
+    HTTPD_BIN    => '/usr/sbin/httpd',
+    HTTPD_CONFIG => realpath( catfile( bz_locations->{confdir}, 'httpd.conf' ) ),
+};
 
 sub catch_signal {
     my ($name, @done)   = @_;
@@ -75,7 +78,7 @@ sub run_cereal {
     my $cereal = IO::Async::Process->new(
         command      => [CEREAL_BIN],
         on_finish    => on_finish($exit_f),
-        on_exception => on_exception( "cereal", $exit_f ),
+        on_exception => on_exception( 'cereal', $exit_f ),
     );
     $exit_f->on_cancel( sub { $cereal->kill('TERM') } );
     $loop->add($cereal);
@@ -85,15 +88,18 @@ sub run_cereal {
 
 sub run_httpd {
     my (@args) = @_;
-    my $loop = IO::Async::Loop->new;
 
+    my $loop   = IO::Async::Loop->new;
     my $exit_f = $loop->new_future;
     my $httpd  = IO::Async::Process->new(
         code => sub {
+
             # we have to setsid() to make a new process group
             # or else apache will kill its parent.
             setsid();
-            exec HTTPD_BIN, '-DFOREGROUND', '-f' => HTTPD_CONFIG, @args;
+            my @command = ( HTTPD_BIN, '-DFOREGROUND', '-f' => HTTPD_CONFIG, @args );
+            exec @command
+              or die "failed to exec $command[0] $!";
         },
         on_finish    => on_finish($exit_f),
         on_exception => on_exception( 'httpd', $exit_f ),
@@ -104,21 +110,52 @@ sub run_httpd {
     return $exit_f;
 }
 
+sub run_jobqueue {
+    my (@args) = @_;
+
+    my $loop     = IO::Async::Loop->new;
+    my $exit_f   = $loop->new_future;
+    my $jobqueue = IO::Async::Process->new(
+        command   => [ JOBQUEUE_BIN, 'start', '-f', '-d', @args ],
+        on_finish => on_finish($exit_f),
+        on_exception => on_exception( 'httpd', $exit_f ),
+    );
+    $exit_f->on_cancel( sub { $jobqueue->kill('TERM') } );
+    $loop->add($jobqueue);
+
+    return $exit_f;
+}
+
+sub run_cereal_and_jobqueue {
+    my (@jobqueue_args) = @_;
+
+    my $signal_f      = catch_signal('TERM', 0);
+    my $cereal_exit_f = run_cereal();
+
+    return assert_cereal()->then(
+        sub {
+            my $jobqueue_exit_f = run_jobqueue(@jobqueue_args);
+            return Future->wait_any($cereal_exit_f, $jobqueue_exit_f, $signal_f);
+        }
+    );
+}
+
 sub run_cereal_and_httpd {
     my @httpd_args = @_;
 
-    push @httpd_args, '-DNETCAT_LOGS';
-    my $signal_f      = catch_signal("TERM", 0);
+    my $signal_f      = catch_signal('TERM', 0);
     my $cereal_exit_f = run_cereal();
 
     return assert_cereal()->then(
         sub {
+            push @httpd_args, '-DNETCAT_LOGS';
+
             my $lc = Bugzilla::Install::Localconfig::read_localconfig();
             if ( ($lc->{inbound_proxies} // '') eq '*' && $lc->{urlbase} =~ /^https/) {
                 push @httpd_args, '-DHTTPS';
             }
             elsif ($lc->{urlbase} =~ /^https/) {
-                WARN("HTTPS urlbase but inbound_proxies is not '*'");
+                WARN('HTTPS urlbase but inbound_proxies is not "*"');
             }
             my $httpd_exit_f  = run_httpd(@httpd_args);
 
@@ -140,24 +177,23 @@ sub assert_httpd {
         my $f = shift;
         ( $f->get =~ /^httpd OK/ );
     };
-    my $timeout = $loop->timeout_future(after => 20)->else_fail("assert_httpd timeout");
+    my $timeout = $loop->timeout_future(after => 20)->else_fail('assert_httpd timeout');
     return Future->wait_any($repeat, $timeout);
 }
 
-
 sub assert_selenium {
     my ($host, $port) = @_;
     $host //= 'localhost';
     $port //= 4444;
 
-    return assert_connect($host, $port, "assert_selenium");
+    return assert_connect($host, $port, 'assert_selenium');
 }
 
 sub assert_cereal {
     return assert_connect(
         'localhost',
         $ENV{LOGGING_PORT} // 5880,
-        "assert_cereal"
+        'assert_cereal'
     );
 }
 
@@ -199,7 +235,7 @@ sub assert_database {
         );
     } until => sub { defined shift->get };
 
-    my $timeout = $loop->timeout_future( after => 20 )->else_fail("assert_database timeout");
+    my $timeout = $loop->timeout_future( after => 20 )->else_fail('assert_database timeout');
     my $any_f = Future->wait_any( $repeat, $timeout );
     return $any_f->transform(
         done => sub { return },
index e04e9c7128adb6ecd00ed23e09442c88097c1c6c..5dfb6fad44a788227b72af620e24e63427c3b406 100644 (file)
@@ -33,6 +33,20 @@ services:
       - bmo-db.vm
       - memcached
 
+  bmo-jobqueue.vm:
+    build: *bmo_build
+    command: jobqueue
+    volumes:
+      - bmo-data-dir:/app/data
+    tmpfs:
+      - /tmp
+      - /run
+    environment: *bmo_env
+    restart: always
+    depends_on:
+      - bmo-db.vm
+      - memcached
+
   bmo-db.vm:
     image: mozillabteam/bmo-mysql:5.6
     volumes:
index 23578e257e69b46c102443f973ab3aa6948b144d..5c981c5c21960471f8d5135b05451cc38908521f 100755 (executable)
@@ -10,6 +10,7 @@ use Bugzilla::Install::Util qw(install_string);
 use Bugzilla::Test::Util qw(create_user);
 use Bugzilla::DaemonControl qw(
     run_cereal_and_httpd
+    run_cereal_and_jobqueue
     assert_httpd assert_database assert_selenium
     on_finish on_exception
 );
@@ -89,6 +90,12 @@ sub cmd_httpd  {
     exit $httpd_exit_f->get();
 }
 
+sub cmd_jobqueue {
+    check_data_dir();
+    wait_for_db();
+    exit run_cereal_and_jobqueue()->get;
+}
+
 sub cmd_dev_httpd {
     my $have_params = -f "/app/data/params";
     assert_database->get();