Skip to content

Commit

Permalink
Use cache_tests from isotovideo engine
Browse files Browse the repository at this point in the history
Move the code a bit to allow the usage of cache_tests method on other
places to avoid code duplication.
  • Loading branch information
foursixnine committed Sep 13, 2017
1 parent 35d2e5b commit e42eb80
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
7 changes: 5 additions & 2 deletions lib/OpenQA/Worker.pm
Expand Up @@ -45,14 +45,15 @@ sub main {
my ($host_settings) = @_;
my $lockfd = lockit();
my $dir;
my $shared_cache;
clean_pool();
## register worker at startup to all webuis
for my $h (@{$host_settings->{HOSTS}}) {
# check if host`s working directory exists
# if caching is not enabled

if ($worker_settings->{CACHEDIRECTORY}) {
prepare_cache_directory($h, $worker_settings->{CACHEDIRECTORY});
$shared_cache = prepare_cache_directory($h, $worker_settings->{CACHEDIRECTORY});
}

my @dirs = ($host_settings->{$h}{SHARE_DIRECTORY}, catdir($OpenQA::Utils::prjdir, 'share'));
Expand All @@ -64,7 +65,9 @@ sub main {

log_debug("Using dir $dir for host $h") if $verbose;
Mojo::IOLoop->next_tick(
sub { OpenQA::Worker::Common::register_worker($h, $dir, $host_settings->{$h}{TESTPOOLSERVER}) });
sub {
OpenQA::Worker::Common::register_worker($h, $dir, $host_settings->{$h}{TESTPOOLSERVER}, $shared_cache);
});
}

# start event loop - this will block until stop is called
Expand Down
24 changes: 4 additions & 20 deletions lib/OpenQA/Worker/Commands.pm
Expand Up @@ -17,12 +17,11 @@ package OpenQA::Worker::Commands;
use 5.018;
use warnings;

use OpenQA::Utils qw(log_error log_warning log_debug log_info);
use OpenQA::Utils qw(log_error log_warning log_debug);
use OpenQA::Worker::Common;
use OpenQA::Worker::Jobs;
use POSIX qw(:sys_wait_h);
use File::Spec::Functions 'catdir';
use Mojo::URL;
use OpenQA::Worker::Engines::isotovideo;

## WEBSOCKET commands
sub websocket_commands {
Expand Down Expand Up @@ -80,28 +79,13 @@ sub websocket_commands {
}
elsif ($type eq 'reload_needles_and_retry') {
if (backend_running) {

if ($hosts->{$current_host}{testpoolserver} && $worker_settings->{CACHEDIRECTORY}) {
# my attempts to use ioloop::subprocess failed, so go back to blocking
my $shared_cache = catdir($worker_settings->{CACHEDIRECTORY}, Mojo::URL->new($current_host)->host);
if ($hosts->{$current_host}{testpoolserver} && $hosts->{$host}{shared_cache}) {
my $sync_child = fork();
if (!$sync_child) {
OpenQA::Worker::Engines::isotovideo::cache_tests($shared_cache,
OpenQA::Worker::Engines::isotovideo::cache_tests($hosts->{$host}{shared_cache},
$hosts->{$current_host}{testpoolserver});
}
else {
my $last_update = time;
while (waitpid($sync_child, WNOHANG) == 0) {
log_info "Waiting for subprocess";
if (time - $last_update > 5) { # do not spam the webui
update_setup_status;
$last_update = time;
}
sleep .5;
}
}
}

$ua->post("$joburl/isotovideo/reload_needles");
log_debug('needles will be reloaded') if $verbose;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenQA/Worker/Common.pm
Expand Up @@ -409,7 +409,7 @@ sub call_websocket {
}

sub register_worker {
my ($host, $dir, $testpoolserver) = @_;
my ($host, $dir, $testpoolserver, $shared_cache) = @_;
die unless $host;
$hosts->{$host}{accepting_jobs} = 0;

Expand Down Expand Up @@ -439,6 +439,7 @@ sub register_worker {

# test pool is from config, so it doesn't change
$hosts->{$host}{testpoolserver} = $testpoolserver if $testpoolserver;
$hosts->{$host}{shared_cache} = $shared_cache if $shared_cache;

# reset workerid
$hosts->{$host}{workerid} = undef;
Expand Down

0 comments on commit e42eb80

Please sign in to comment.