Skip to content

Instantly share code, notes, and snippets.

@sugar84
Created September 22, 2011 12:06
Show Gist options
  • Select an option

  • Save sugar84/1234627 to your computer and use it in GitHub Desktop.

Select an option

Save sugar84/1234627 to your computer and use it in GitHub Desktop.
separate script
#!/usr/bin/env perl
use common::sense;
use lib qw(./lib);
use MojoX::Run;
use Data::Dumper;
my $run = MojoX::Run->new;
my $all = { sda => 11, sdb => 22, sdc => 11, sdd => 22, sde => 11, sdf => 22, sdg => 33 };
my $master = {disk => "sdb"};
my $count = scalar keys %$all;
my (@shas, $i);
for my $disk (keys %$all) {
my $pid = $run->spawn(
cmd => sub {
# my @shas =
# map {/^([0-9a-f]+)/}
# qx(find $dest/$part -type f | grep -Fv "lost+found" | sort | xargs shasum)
# ;
# print "_\__" . join("", @shas) . "__/_";
print "_\__hello world!__/_";
# sleep 1;
exit 0;
},
exec_timeout => 60 * 60 * 4,
exit_cb => sub {
my ($pid, $res) = @_;
utf8::upgrade($_) for grep { $_ } @$res{qw(error stderr stdout)};
my ($sha) = $res->{stdout} =~ m{_\__(.*)__/_};
if ($disk eq $master->{disk}) {
unshift @shas, [ $sha, $disk, {%$res, pid => $pid} ];
} else {
push @shas, [ $sha, $disk, {%$res, pid => $pid} ];
}
$run->ioloop->stop if ++$i == $count;
},
);
}
$run->ioloop->start;
open my $fh, ">", "dump" or die $!;
print {$fh} Dumper( \@shas );
__END__
# cat dump:
$VAR1 = [
[
'hello world!',
'sdb',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.8179',
'time_started' => '1316693014.78476',
'time_duration_total' => '0.0434551239013672',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9108,
'exit_signal' => 9,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0331361293792725'
}
],
[
'hello world!',
'sda',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.80793',
'time_started' => '1316693014.77702',
'time_duration_total' => '0.0505080223083496',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9106,
'exit_signal' => 0,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0309090614318848'
}
],
[
'hello world!',
'sdg',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.80454',
'time_started' => '1316693014.78071',
'time_duration_total' => '0.0481040477752686',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9107,
'exit_signal' => 9,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0238320827484131'
}
],
[
'hello world!',
'sdc',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.80426',
'time_started' => '1316693014.77234',
'time_duration_total' => '0.0568840503692627',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9105,
'exit_signal' => 0,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0319221019744873'
}
],
[
'hello world!',
'sde',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.77488',
'time_started' => '1316693014.76734',
'time_duration_total' => '0.062614917755127',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9104,
'exit_signal' => 0,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.00753903388977051'
}
],
[
'hello world!',
'sdd',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.82471',
'time_started' => '1316693014.8052',
'time_duration_total' => '0.0259199142456055',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9109,
'exit_signal' => 0,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0195119380950928'
}
],
[
'hello world!',
'sdf',
{
'cmd' => 'CODE',
'stderr' => '',
'time_stopped' => '1316693014.84354',
'time_started' => '1316693014.81554',
'time_duration_total' => '0.0282020568847656',
'exit_status' => 0,
'exit_core' => 0,
'pid' => 9110,
'exit_signal' => 0,
'error' => undef,
'stdout' => '___hello world!__/_',
'time_duration_exec' => '0.0280001163482666'
}
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment