I have written a function and the function call works as expected and i get the desired output when i make the function call. However I'd like to enhance it by making a couple of changes to it. For now the function takes 'ip'
and 'service names'
as arguments.
Enhancement : 1 ) When i make the function call and if i do not pass any services as arguments, I want the function to take all the services as arguments by itself There are totally 5 services. say for example service1, service2,service3,service 6,service8.(These are just sample names.it could be anything). So what is the change that i need to make to the function to ensure that if services are not passed as arguments, The function must take all the services as arguments.
Eg Function call :
$self->{'status_of_services'} = $self->{'services_obj'}->health_check('ip')
So when the above function call is made all the function must take all the services as arguments
Enhancement.2) user wants to pass one or two services as arguments in the function call. currently i store them in an array. like @services = ('service1','service2','service3')
.I do not want to store them in an array.instead i want to pass the services as arguments directly like below. Any suggestions please.
eg : $self->{'status_of_services'} = $self->{'services_obj'}->health_check('ip', [service1 ,service2]);
Function :
sub health_check{
my ($self, $ip, @service_name) = @_;
$self->{'health_checks_obj'} = ServiceManager->new( ip => $ip );
$self->{'services_status'} = $self->{'health_checks_obj'}->isRunning( {service => @service_name} );
sleep(5);
if ( not $self->{'services_status'} ) {
$self->{'health_checks_obj'}->start( {service => @service_name , timeout => '30'} );
sleep (3);
}
return 1 ;
}
Function call :
my @services = ('service1', 'service2', 'service3','service4','service5');
$self->{'status_of_services'} = $self->{'services_obj'}->health_check('ip', @services);
INFO (' Health check result is : ' . $self->{'status_of_services'} );
Output :
Health check result is : 1