P2-Scheduler

 view release on metacpan or  search on metacpan

lib/P2/Scheduler.pm  view on Meta::CPAN

package P2::Scheduler;

use v5.18;
our $VERSION = '0.07';

use Moose;
use POSIX       qw(ceil);
use UUID        qw(uuid);
use Date::Calc  qw(
    Days_in_Month
    Day_of_Week
);

# resources per priority
has 'resources' => (is => 'ro', isa => 'ArrayRef', required => 1);

# the type of resource
has 'resource_type' => (is => 'ro', isa => 'Str', default => 'namespace');

# how many tests per priority per day
has 'weight'     => (is => 'rw', isa => 'ArrayRef', default => sub {[3,2,1]});

# use this to set the hours in the testing slot
has 'hour_slots' => (is => 'rw', isa => 'ArrayRef', default => sub {[1,2,3,4,5]} );
has 'fixed_intervals' => ( is => 'rw', isa => 'Bool', default => 0 );

has 'year'       => (is => 'rw', isa => 'Int', default => 2020);

# this to set to run P3 and P2 tests only on selected months
# defaults to run all tests for all priorities all year round
has 'pri_per_month' => (is => 'rw', isa => 'ArrayRef', default => sub{ return [3,3,3,3,3,3,3,3,3,3,3,3]});

# this to leave some spare days at the end of the month to reschedule tests
# defaults to 0 spare days
has 'spare_days_per_month' => (is => 'rw', isa => 'Int', default => 0);

# this to start right not at the first business day of the month
# usefull when you reschedule things in between...
has 'starting_from' => (is => 'rw', isa => 'Int', default => 0);

# use this if you want to limit the number of testing days in a week, always starting
# from Monday, defaults to 5 (Monday to Friday)
has 'num_week_days' => (is => 'rw', isa => 'Int', default => 5); 

# use this if you want to select the business days to run the tests
# 1 => Monday,..., 5 => Friday
has 'selected_week_days' => (is => 'rw', isa => 'ArrayRef', default => sub{ return [1,2,3,4,5] });

# the Kubernetes (or any other means to address the proper cloud) context...
has 'context' => (is => 'rw', isa => 'Str');

# Label to be added to resource and context to derive experiment unique name...
has 'label' => (is => 'rw', isa => 'Str', default => "");

# a description of what is happening to the resource, it will appear as title
has 'action' => (is => 'rw', isa => 'Str', default => "No action specified");


sub BUILD {
    my $self = shift;

    $self->{tot_mins} = ($self->{hour_slots}->[-1] - $self->{hour_slots}->[0]) * 60;
    my $tot_experiments = eval join '+', @{$self->{weight}};
    $self->{mins_interval} = $self->{tot_mins} / $tot_experiments;
}

sub year_schedule {
    my $self = shift;

    my @year_schedule = ();
    for (1..12) {
        push @year_schedule, $self->month_schedule($_);
    }
    return @year_schedule;
}



( run in 0.825 second using v1.01-cache-2.11-cpan-39bf76dae61 )