Beam-Runner
view release on metacpan or search on metacpan
pre-check so only certain users can run a script.
- Added Beam::Runnable::DenyUsers role to provide a simple pre-check
so certain users are not allowed to run a script.
- Added Beam::Runnable::Single role to ensure a task is only able to
be run once at a time.
0.011 2017-06-09 01:48:33-05:00 America/Chicago
[Added]
- Beam::Runnable::Timeout::Alarm role allows easily adding timeouts
to runnable modules.
- Added quickstart tutorial for getting started using Beam::Runner.
[Fixed]
- Fixed `beam help` command showing the `beam` command documentation
if the given task has no documentation. Now it correctly shows an
error message instead.
README
bin/beam
cpanfile
dist.ini
eg/quickstart/etc/greet.yml
eg/quickstart/lib/My/Runnable/Greeting.pm
lib/Beam/Runnable.pm
lib/Beam/Runnable/AllowUsers.pm
lib/Beam/Runnable/DenyUsers.pm
lib/Beam/Runnable/Single.pm
lib/Beam/Runnable/Timeout/Alarm.pm
lib/Beam/Runner.pm
lib/Beam/Runner/Command.pm
lib/Beam/Runner/Command/help.pm
lib/Beam/Runner/Command/list.pm
lib/Beam/Runner/Command/run.pm
lib/Beam/Runner/ExecCommand.pm
lib/Beam/Runner/Steps.pm
lib/Beam/Runner/Util.pm
t/00-compile.t
t/00-report-prereqs.dd
"version" : "0.016"
},
"Beam::Runnable::DenyUsers" : {
"file" : "lib/Beam/Runnable/DenyUsers.pm",
"version" : "0.016"
},
"Beam::Runnable::Single" : {
"file" : "lib/Beam/Runnable/Single.pm",
"version" : "0.016"
},
"Beam::Runnable::Timeout::Alarm" : {
"file" : "lib/Beam/Runnable/Timeout/Alarm.pm",
"version" : "0.016"
},
"Beam::Runner" : {
"file" : "lib/Beam/Runner.pm",
"version" : "0.016"
},
"Beam::Runner::Command" : {
"file" : "lib/Beam/Runner/Command.pm",
"version" : "0.016"
},
version: '0.016'
Beam::Runnable::AllowUsers:
file: lib/Beam/Runnable/AllowUsers.pm
version: '0.016'
Beam::Runnable::DenyUsers:
file: lib/Beam/Runnable/DenyUsers.pm
version: '0.016'
Beam::Runnable::Single:
file: lib/Beam/Runnable/Single.pm
version: '0.016'
Beam::Runnable::Timeout::Alarm:
file: lib/Beam/Runnable/Timeout/Alarm.pm
version: '0.016'
Beam::Runner:
file: lib/Beam/Runner.pm
version: '0.016'
Beam::Runner::Command:
file: lib/Beam/Runner/Command.pm
version: '0.016'
Beam::Runner::Command::help:
file: lib/Beam/Runner/Command/help.pm
version: '0.016'
Tasks
A task is an object that consumes the Beam::Runnable role. This role
requires only a "run()" method be implemented in the class. This "run()"
method should accept all the arguments given on the command line. It can
parse GNU-style options out of this array using "GetOptionsFromArray" in
Getopt::Long.
Task modules can compose additional roles to easily add more features,
like adding a timeout with Beam::Runnable::Timeout::Alarm.
Task modules are expected to have documentation that will be displayed
by the "beam list" and "beam help" commands. The "beam list" command
will display the "NAME" section of the documentation, and the "beam
help" command will display the "NAME", "SYNOPSIS", "DESCRIPTION",
"ARGUMENTS", "OPTIONS", "ENVIRONMENT", and "SEE ALSO" sections of the
documentation.
Configuration Files
lib/Beam/Runnable.pm view on Meta::CPAN
#pod either the C<summary> attribute or the C<NAME> POD section (abstract)
#pod next to the service name.
#pod
#pod =head2 Additional Roles
#pod
#pod Additional roles can add common functionality to your runnable script.
#pod Some of these are included in the C<Beam::Runner> distribution:
#pod
#pod =over
#pod
#pod =item L<Beam::Runnable::Timeout::Alarm>
#pod
#pod This role will add a timeout using Perl's built-in
#pod L<alarm()|perlfunc/alarm> function. Once the timeout is reached, the
#pod program will print a warning and exit with an error code.
#pod
#pod =back
#pod
#pod =head1 SEE ALSO
#pod
#pod L<beam>, L<Beam::Runner>
lib/Beam/Runnable.pm view on Meta::CPAN
either the C<summary> attribute or the C<NAME> POD section (abstract)
next to the service name.
=head2 Additional Roles
Additional roles can add common functionality to your runnable script.
Some of these are included in the C<Beam::Runner> distribution:
=over
=item L<Beam::Runnable::Timeout::Alarm>
This role will add a timeout using Perl's built-in
L<alarm()|perlfunc/alarm> function. Once the timeout is reached, the
program will print a warning and exit with an error code.
=back
=head1 ATTRIBUTES
=head2 summary
lib/Beam/Runnable/Timeout/Alarm.pm view on Meta::CPAN
package Beam::Runnable::Timeout::Alarm;
our $VERSION = '0.016';
# ABSTRACT: Use `alarm` to set a timeout for a command
#pod =head1 SYNOPSIS
#pod
#pod ### In a Runnable module
#pod package My::Runnable::Script;
#pod use Moo;
#pod with 'Beam::Runnable', 'Beam::Runnable::Timeout::Alarm';
#pod has '+timeout' => ( default => 60 ); # Set timeout: 60s
#pod sub run { }
#pod
#pod ### In a container config file
#pod runnable:
#pod $class: My::Runnable::Script
#pod $with:
#pod - 'Beam::Runnable::Timeout::Alarm'
#pod timeout: 60
#pod
#pod =head1 DESCRIPTION
#pod
#pod This role adds a timeout for a runnable module using Perl's L<alarm()|perlfunc/alarm>
#pod function. When the timeout is reached, a warning will be printed to C<STDERR> and the
#pod program will exit with code C<255>.
#pod
#pod =head1 SEE ALSO
#pod
lib/Beam/Runnable/Timeout/Alarm.pm view on Meta::CPAN
#pod A callback to be run when the timeout is reached. Override this to change
#pod what warning is printed to C<STDERR> and what exit code is used (or whether
#pod the process exits at all).
#pod
#pod =cut
has _timeout_cb => (
is => 'ro',
isa => CodeRef,
default => sub {
warn "Timeout reached!\n";
exit 255;
},
);
#pod =method run
#pod
#pod This role wraps the C<run> method of your runnable class to add the timeout.
#pod
#pod =cut
lib/Beam/Runnable/Timeout/Alarm.pm view on Meta::CPAN
};
1;
__END__
=pod
=head1 NAME
Beam::Runnable::Timeout::Alarm - Use `alarm` to set a timeout for a command
=head1 VERSION
version 0.016
=head1 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
=head1 DESCRIPTION
This role adds a timeout for a runnable module using Perl's L<alarm()|perlfunc/alarm>
function. When the timeout is reached, a warning will be printed to C<STDERR> and the
program will exit with code C<255>.
=head1 ATTRIBUTES
lib/Beam/Runner.pm view on Meta::CPAN
#pod
#pod =head2 Tasks
#pod
#pod A task is an object that consumes the L<Beam::Runnable> role. This role
#pod requires only a C<run()> method be implemented in the class. This
#pod C<run()> method should accept all the arguments given on the command
#pod line. It can parse GNU-style options out of this array using
#pod L<Getopt::Long/GetOptionsFromArray>.
#pod
#pod Task modules can compose additional roles to easily add more features,
#pod like adding a timeout with L<Beam::Runnable::Timeout::Alarm>.
#pod
#pod Task modules are expected to have documentation that will be displayed
#pod by the C<beam list> and C<beam help> commands. The C<beam list> command
#pod will display the C<NAME> section of the documentation, and the C<beam
#pod help> command will display the C<NAME>, C<SYNOPSIS>, C<DESCRIPTION>,
#pod C<ARGUMENTS>, C<OPTIONS>, C<ENVIRONMENT>, and C<SEE ALSO> sections of
#pod the documentation.
#pod
#pod =head2 Configuration Files
#pod
lib/Beam/Runner.pm view on Meta::CPAN
=head2 Tasks
A task is an object that consumes the L<Beam::Runnable> role. This role
requires only a C<run()> method be implemented in the class. This
C<run()> method should accept all the arguments given on the command
line. It can parse GNU-style options out of this array using
L<Getopt::Long/GetOptionsFromArray>.
Task modules can compose additional roles to easily add more features,
like adding a timeout with L<Beam::Runnable::Timeout::Alarm>.
Task modules are expected to have documentation that will be displayed
by the C<beam list> and C<beam help> commands. The C<beam list> command
will display the C<NAME> section of the documentation, and the C<beam
help> command will display the C<NAME>, C<SYNOPSIS>, C<DESCRIPTION>,
C<ARGUMENTS>, C<OPTIONS>, C<ENVIRONMENT>, and C<SEE ALSO> sections of
the documentation.
=head2 Configuration Files
t/00-compile.t view on Meta::CPAN
use Test::More;
plan tests => 14 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
my @module_files = (
'Beam/Runnable.pm',
'Beam/Runnable/AllowUsers.pm',
'Beam/Runnable/DenyUsers.pm',
'Beam/Runnable/Single.pm',
'Beam/Runnable/Timeout/Alarm.pm',
'Beam/Runner.pm',
'Beam/Runner/Command.pm',
'Beam/Runner/Command/help.pm',
'Beam/Runner/Command/list.pm',
'Beam/Runner/Command/run.pm',
'Beam/Runner/ExecCommand.pm',
'Beam/Runner/Steps.pm',
'Beam/Runner/Util.pm'
);
t/timeout/alarm.t view on Meta::CPAN
=head1 DESCRIPTION
This file tests the L<Beam::Runnable::Timeout::Alarm> class to ensure it
times out correctly.
=head1 SEE ALSO
L<Beam::Runnable::Timeout::Alarm>
=cut
use strict;
use warnings;
use Test::More;
my $RUNNING = 1;
{ package
t::Timeout::Alarm;
use Moo;
with 'Beam::Runnable', 'Beam::Runnable::Timeout::Alarm';
sub run {
while ( $RUNNING ) { sleep 1 }
}
}
subtest 'test timeout' => sub {
my $flag = 0;
my $foo = t::Timeout::Alarm->new(
timeout => 0.1,
_timeout_cb => sub {
$RUNNING = 0;
},
);
$foo->run;
ok !$RUNNING, 'timeout reached';
};
done_testing;
( run in 0.332 second using v1.01-cache-2.11-cpan-0d8aa00de5b )