Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: More signatures #5511

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/OpenQA/Resource/Jobs.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Copyright 2017-2020 SUSE LLC
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package OpenQA::Resource::Jobs;

use strict;
use warnings;
use Mojo::Base -strict, -signatures;

use OpenQA::Jobs::Constants;
use OpenQA::Schema;
Expand All @@ -26,8 +25,7 @@ Handle job restart by user (using API or WebUI). Job is only restarted when eith
or done. Scheduled jobs can't be restarted.

=cut
sub job_restart {
my ($jobids, %args) = @_;
sub job_restart ($jobids, %args) {
my (@duplicates, @processed, @errors, @warnings);
my %res = (duplicates => \@duplicates, errors => \@errors, warnings => \@warnings, enforceable => 0);
unless (ref $jobids eq 'ARRAY' && @$jobids) {
Expand Down
36 changes: 11 additions & 25 deletions lib/OpenQA/Resource/Locks.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Copyright 2015-2019 SUSE LLC
# Copyright SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later

package OpenQA::Resource::Locks;

use strict;
use warnings;
use Mojo::Base -strict, -signatures;

use OpenQA::Jobs::Constants;
use OpenQA::Schema;
Expand All @@ -21,8 +20,7 @@ my %final_states = map { $_ => 1 } OpenQA::Jobs::Constants::NOT_OK_RESULTS();
# So we have to specify, which child job is supposed to create the lock
# and watch it's state.
#
sub _get_lock {
my ($name, $jobid, $where) = @_;
sub _get_lock ($name = undef, $jobid = undef, $where = undef) {
return 0 unless defined $name && defined $jobid;
my $schema = OpenQA::Schema->singleton;
my $job = $schema->resultset('Jobs')->single({id => $jobid});
Expand All @@ -45,9 +43,7 @@ sub _get_lock {
}

# returns -1 on unrecoverable error, 1 on have lock, 0 on try later (lock unavailable)
sub lock {
my ($name, $jobid, $where) = @_;

sub lock ($name, $jobid, $where) {
my $lock = _get_lock($name, $jobid, $where);

if (!$lock and $where =~ /^\d+$/) {
Expand All @@ -70,8 +66,7 @@ sub lock {
return 0;
}

sub unlock {
my ($name, $jobid, $where) = @_;
sub unlock ($name, $jobid, $where = undef) {
my $lock = _get_lock($name, $jobid, $where // 'all');
return 0 unless $lock;
# return if not locked
Expand All @@ -82,8 +77,7 @@ sub unlock {
return 0;
}

sub create {
my ($name, $jobid) = @_;
sub create ($name, $jobid) {
my $lock = _get_lock($name, $jobid, 'all');
# nothing if lock already exist
return 0 if $lock;
Expand All @@ -99,8 +93,7 @@ sub create {
## Barriers
# barriers are created with number of expected jobs. Then wait call waits until the expected number of jobs is waiting

sub barrier_create {
my ($name, $jobid, $expected_jobs) = @_;
sub barrier_create ($name = undef, $jobid = undef, $expected_jobs = undef) {
return 0 unless $name && $jobid && $expected_jobs;
my $barrier = _get_lock($name, $jobid, 'all');
return 0 if $barrier;
Expand All @@ -111,9 +104,7 @@ sub barrier_create {
return $barrier;
}

sub barrier_wait {
my ($name, $jobid, $where, $check_dead_job) = @_;

sub barrier_wait ($name = undef, $jobid = undef, $where = undef, $check_dead_job = 0) {
return -1 unless $name && $jobid;
return -1 unless my $barrier = _get_lock($name, $jobid, $where);

Expand All @@ -130,20 +121,15 @@ sub barrier_wait {
}
}

if (grep { $_ eq $jobid } @jobs) {
return 1 if @jobs == $barrier->count;
return 0;
}
return @jobs == $barrier->count if grep { $_ eq $jobid } @jobs;

push @jobs, $jobid;
$barrier->update({locked_by => join(',', @jobs)});

return 1 if @jobs == $barrier->count;
return 0;
return @jobs == $barrier->count;
}

sub barrier_destroy {
my ($name, $jobid, $where) = @_;
sub barrier_destroy ($name = undef, $jobid = undef, $where = undef) {
return 0 unless $name && $jobid;
my $barrier = _get_lock($name, $jobid, $where);
return 0 unless $barrier;
Expand Down
6 changes: 2 additions & 4 deletions lib/OpenQA/WebAPI/ServerSideDataTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

package OpenQA::WebAPI::ServerSideDataTable;

use strict;
use warnings;
use Mojo::Base -strict, -signatures;

sub render_response {
my (%args) = @_;
sub render_response (%args) {
# mandatory parameter
my $controller = $args{controller};
my $resultset_name = $args{resultset};
Expand Down
11 changes: 2 additions & 9 deletions script/openqa-validate-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,11 @@

print($usage->text), exit if $opt->help;

my @files = @ARGV;
my @files = @ARGV or pass 'Nothing to do';

Check warning on line 46 in script/openqa-validate-yaml

View check run for this annotation

Codecov / codecov/patch

script/openqa-validate-yaml#L46

Added line #L46 was not covered by tests

my $default_schema = "$RealBin/../public/schema/JobTemplates-01.yaml";
my $schema = $opt->schema_file // $default_schema;

unless (@files) {
pass "Nothing to do";
}

if ($opt->validate_schema) {
diag 'Validating schema, too';
}
diag 'Validating schema, too' if $opt->validate_schema;

Check warning on line 50 in script/openqa-validate-yaml

View check run for this annotation

Codecov / codecov/patch

script/openqa-validate-yaml#L50

Added line #L50 was not covered by tests
for my $file (@files) {
my $data;
if ($file eq '-') {
Expand Down
Loading