use strict; use warnings; use v5.10.1; use Step::Base; my ( $steps, $step_names ) = load_steps(); while (1) { my $cnt_not_ready = 0; my $cnt_running = 0; my $cnt_done = 0; FOR: foreach my $name ( @{$step_names} ) { if ( $steps->{$name}->done ) { $cnt_done++; } elsif ( $steps->{$name}->state eq 'Created' ) { if ( $steps->{$name}->ready ) { $steps->{$name}->run ? $cnt_running++ : $cnt_done++; } else { $cnt_not_ready++; } } elsif ( $steps->{$name}->running ) { $cnt_running++; } else { die "Something ain't right!\n" . "$name\-\>state = " . $steps->{$name}->state . "\n" . "\tRunning: " . $steps->{$name}->running . "\n" . "\t Done: " . $steps->{$name}->done . "\n"; } printf( "%-15s %s\n", $steps->{$name}->state, $name ); } printf( "Not Ready: %d Running: %d Done: %d\n", $cnt_not_ready, $cnt_running, $cnt_done ); last if ( $cnt_done >= scalar( @{$step_names} ) ); sleep(5); } sub load_steps { my $steps; my $step_names; my $conf = define_steps_conf(); foreach my $step ( @{$conf} ) { my ( $name, $args ) = each %{$step}; $args->{name} = $name; $args->{steps} = $steps; my $s = Step::Base->new($args); $steps->{$name} = $s; push( @{$step_names}, $name ); 1; } return ( $steps, $step_names ); } ## ---------- end sub load_steps sub define_steps_conf { my $steps = [ { 'Action01' => { code_to_run => 'main::do_nothing', predecessors => [], } }, { 'Action01a', => { code_to_run => 'main::do_nothing', predecessors => [ 'Action01', ], } }, { 'Action02' => { code_to_run => 'main::do_nothing', predecessors => [], } }, { 'Action02a' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action02', ], } }, { 'Action03' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action01a', 'Action02a', ], } }, { 'Action04' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action03', ], } }, { 'Action05' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action04', ], } }, { 'Action06' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action05', ], } }, { 'Action07' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action05', ], } }, { 'Action08' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action06', 'Action07' ], } }, { 'Action09' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action08', ], } }, { 'Action10' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action01a', 'Action02a' ], } }, { 'Action11' => { code_to_run => 'main::do_nothing', predecessors => [ 'Action08', ], } }, ]; return ($steps); } ## ---------- end sub define_steps_conf sub do_nothing { sleep int( rand(5) + 5.5 ); if ( int( rand() + 0.9 ) ) { # fail 10% of the time return ( { success => 1 } ); } else { return ( { success => 0, err_msg => "I screw up" } ); } } ## ---------- end sub do_nothing