Continual-Process
view release on metacpan or search on metacpan
lib/Continual/Process/Instance.pm view on Meta::CPAN
$instance = Continual::Process::Instance->new(
name => 'job1',
instance_id => 1,
code => sub {
...
return $pid;
}
)->start();
while(1) {
if (!$instance->is_alive()) {
$instance->start();
}
}
=head1 DESCRIPTION
This class represents one instance of L<Continual::Process>
=head1 METHODS
lib/Continual/Process/Instance.pm view on Meta::CPAN
if (!defined $pid) {
die 'Undefined PID';
}
if ($pid !~ /^(?:-)?\d+$/) {
die "Returned PID ($pid) " . $self->name . " isn't number!";
}
return $pid;
}
=head2 is_alive()
is this instance alive?
=cut
sub is_alive {
my ($self) = @_;
return defined $self->pid && !waitpid $self->pid, WNOHANG;
}
sub DESTROY {
my ($self) = @_;
# destroy only in parent (main) process
# ignore pseudo-process (<0) is threads and threads died with main
lib/Continual/Process/Loop.pm view on Meta::CPAN
=head2 new(%attributes)
=head3 %attributes
=head4 instances
I<ArrayRef> of instances - default is empty (C<[]>)
=head4 interval
interval of alive checking
default is I<1>sec
=head4 on_interval
CodeRef which is called each check interval
default is I<disabled>
=head2 add($instance)
lib/Continual/Process/Loop.pm view on Meta::CPAN
die "Method run must be implemented";
}
sub _check_and_run_death {
my ($self) = @_;
$self->on_interval->() if defined $self->on_interval;
foreach my $task (@{ $self->instances }) {
if (!$task->is_alive) {
$task->start();
}
}
}
=head1 LICENSE
Copyright (C) Avast Software.
This library is free software; you can redistribute it and/or modify
t/Continual/Process/Instance.t view on Meta::CPAN
sleep 10;
exit 1;
}
);
lives_ok {
$proc->start();
} 'start';
ok($proc->is_alive(), 'process is alive');
#destroy check
undef $proc;
$proc = Continual::Process::Instance->new(
name => 'test',
instance_id => 1,
code => sub {
return $pid;
}
);
ok(!$proc->is_alive(), 'proccess is death after destruction');
( run in 0.889 second using v1.01-cache-2.11-cpan-39bf76dae61 )