@@ -6,6 +6,7 @@ our $VERSION = '1.000132';
6
6
7
7
use Term::Table();
8
8
use File::Spec();
9
+ use Time::HiRes qw/ sleep/ ;
9
10
10
11
use App::Yath::Util qw/ find_pfile/ ;
11
12
@@ -29,26 +30,47 @@ A look at the state and resources used by a runner.
29
30
30
31
sub pfile_params { (no_fatal => 1) }
31
32
33
+ sub newest {
34
+ my ($a , $b ) = @_ ;
35
+ return $a unless $b ;
36
+ return $b unless $a ;
37
+
38
+ my @as = stat ($a );
39
+ my @bs = stat ($b );
40
+ return $a if $as [9] > $bs [9];
41
+ return $b ;
42
+ }
43
+
32
44
sub state {
33
45
my $self = shift ;
34
46
35
47
return $self -> {+STATE} if $self -> {+STATE};
36
48
37
- if (-e ' ./.test_info.json' ) {
38
- my $data = Test2::Harness::Util::File::JSON-> new(name => ' ./.test_info.json' )-> read ;
39
- return $self -> {+STATE} = Test2::Harness::Runner::State-> new(%$data );
49
+ my $info_file ;
50
+ opendir (my $dh , " ./" ) or die " Could not open current dir: $! " ;
51
+ for my $file (readdir ($dh )) {
52
+ next unless $file =~ m { ^\. test_info\.\S +\. json$} ;
53
+ $info_file = newest($info_file , " ./$file " );
40
54
}
41
55
42
- if (my $pfile = find_pfile($self -> settings, no_fatal => 1)) {
43
- my $data = Test2::Harness::Util::File::JSON-> new(name => $pfile )-> read ();
44
- my $workdir = $data -> {dir };
45
- my $settings = Test2::Harness::Util::File::JSON-> new(name => " $workdir /settings.json" )-> read ();
56
+ my $pfile = find_pfile($self -> settings, no_fatal => 1);
46
57
47
- return $self -> {+STATE} = Test2::Harness::Runner::State-> new(
48
- job_count => $settings -> {runner }-> {job_count } // 1,
49
- workdir => $data -> {dir },
50
- settings => $settings ,
51
- );
58
+ if (my $use = newest($info_file , $pfile )) {
59
+ if ($info_file ) {
60
+ my $data = Test2::Harness::Util::File::JSON-> new(name => $info_file )-> read ;
61
+ return $self -> {+STATE} = Test2::Harness::Runner::State-> new(%$data );
62
+ }
63
+
64
+ if (my $pfile = find_pfile($self -> settings, no_fatal => 1)) {
65
+ my $data = Test2::Harness::Util::File::JSON-> new(name => $pfile )-> read ();
66
+ my $workdir = $data -> {dir };
67
+ my $settings = Test2::Harness::Util::File::JSON-> new(name => " $workdir /settings.json" )-> read ();
68
+
69
+ return $self -> {+STATE} = Test2::Harness::Runner::State-> new(
70
+ job_count => $settings -> {runner }-> {job_count } // 1,
71
+ workdir => $data -> {dir },
72
+ );
73
+ }
52
74
}
53
75
54
76
die " No persistent runner, and no running test found.\n " ;
@@ -58,16 +80,21 @@ sub run {
58
80
my $self = shift ;
59
81
60
82
my $state = $self -> state;
61
- $state -> poll;
62
-
63
- print " \n ==== Resource state ====\n " ;
64
- for my $resource (@{$state -> resources}) {
65
- my @lines = $resource -> status_lines;
66
- next unless @lines ;
67
- print " \n Resource: " . ref ($resource ) . " \n " ;
68
- print join " \n " => @lines ;
83
+
84
+ while (1) {
85
+ $state -> poll;
86
+
87
+ print " \r\e [2J\r\e [1;1H" ;
88
+ print " \n ==== Resource state ====\n " ;
89
+ for my $resource (@{$state -> resources}) {
90
+ my @lines = $resource -> status_lines;
91
+ next unless @lines ;
92
+ print " \n Resource: " . ref ($resource ) . " \n " ;
93
+ print join " \n " => @lines ;
94
+ }
95
+ print " \n\n " ;
96
+ sleep 0.1;
69
97
}
70
- print " \n\n " ;
71
98
72
99
return 0;
73
100
}
0 commit comments