App-karr
view release on metacpan or search on metacpan
lib/App/karr/Foundation.pm view on Meta::CPAN
sub _lock_file { path( $_[1]->child('.karr.lock') ) }
sub _lock_held {
my ( $self, $repo ) = @_;
my $lock = $self->_lock_file( $repo );
return 0 unless $lock->exists;
my $pid = $lock->slurp_utf8;
chomp $pid;
return 0 unless $pid =~ /^\d+$/;
# Check if PID is alive
return kill( 0, $pid ) ? 1 : 0;
}
sub _acquire_lock {
my ( $self, $repo ) = @_;
return if $self->dry_run;
$self->_lock_file( $repo )->spew_utf8( "$$\n" );
}
sub _release_lock {
t/30-foundation.t view on Meta::CPAN
}
sub write_karr_file {
my ( $dir, %opts ) = @_;
my $content = "command: " . ( $opts{command} // 'echo hello' ) . "\n";
$content .= "on_idle: " . ( $opts{on_idle} // 'skip' ) . "\n";
$content .= "max_runtime: " . ( $opts{max_runtime} // 1800 ) . "\n";
$dir->child('.karr')->spew_utf8( $content );
}
# Returns ($cfg_dir, $cfg_file) â caller must keep $cfg_dir alive to avoid cleanup
sub write_config {
my ( $dirs ) = @_;
my $cfg_dir = tempdir( CLEANUP => 1 );
my $cfg_file = $cfg_dir->child('config.yml');
$cfg_file->spew_utf8( "dirs:\n" . join( '', map { " - $_\n" } @$dirs ) );
return ( $cfg_dir, $cfg_file );
}
# ---------------------------------------------------------------------------
# Compilation
( run in 0.870 second using v1.01-cache-2.11-cpan-df04353d9ac )