NAME

Beam::Runnable::Timeout::Alarm - Use `alarm` to set a timeout for a command

VERSION

version 0.016

SYNOPSIS

### In a Runnable module
package My::Runnable::Script;
use Moo;
with 'Beam::Runnable', 'Beam::Runnable::Timeout::Alarm';
has '+timeout' => ( default => 60 ); # Set timeout: 60s
sub run { }

### In a container config file
runnable:
    $class: My::Runnable::Script
    $with:
        - 'Beam::Runnable::Timeout::Alarm'
    timeout: 60

DESCRIPTION

This role adds a timeout for a runnable module using Perl's alarm() function. When the timeout is reached, a warning will be printed to STDERR and the program will exit with code 255.

ATTRIBUTES

timeout

The time in seconds this program is allowed to run. This can include a decimal (like 6.5 seconds).

_timeout_cb

A callback to be run when the timeout is reached. Override this to change what warning is printed to STDERR and what exit code is used (or whether the process exits at all).

METHODS

run

This role wraps the run method of your runnable class to add the timeout.

SEE ALSO

Beam::Runnable, "alarm" in perlfunc, Time::HiRes

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Doug Bell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.