7 StartJob( $type, $name, $deleteafter );
9 EndJob( $fail ); # Fail is optional. If fail is not supplied, it is set based on whether there was any output on stderr from the job.
11 DeleteJob( $type, $name ); # Used to expire old jobs.
13 Keep the following info about a job:
18 duration (int seconds)
25 type+name must be unique.
27 Between StartJob and EndJob, N::L::error is logged
28 and subsequently stored in the message field. This is true regardless
29 of the use of --verbose parameters. If any errors are logged,
30 the job is regarded as failed (success=0)
37 our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
41 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
42 @EXPORT_OK = qw
/StartJob EndJob/;
47 use NonameTV
::Factory qw
/CreateDataStore/;
48 use NonameTV
::Log qw
/StartLogSection EndLogSection/;
55 my( $type, $name, $deleteafter ) = @_;
57 die "StartJob called twice" if defined $curr;
59 my $ddt = DateTime
->now()->add( days
=> $deleteafter );
64 starttime
=> DateTime
->now(),
65 deleteafter
=> $ddt->ymd() . " " . $ddt->hms(),
68 StartLogSection
( $name, 1 );
72 die if not defined $curr;
74 my $message = EndLogSection
( $curr->{name
} );
78 $curr->{success
} = $message eq "";
79 $curr->{message
} = $message;
81 my $duration = DateTime
->now()->subtract_datetime_absolute(
84 $curr->{duration
} = $duration->delta_seconds();
85 $curr->{starttime
} = $curr->{starttime
}->ymd() . " " .
86 $curr->{starttime
}->hms();
88 if( $curr->{success
} ) {
89 $curr->{lastok
} = $curr->{starttime
};
92 $curr->{lastfail
} = $curr->{starttime
};
95 my $ds = CreateDataStore
();
97 if( $ds->sa->Update( "jobs", { type
=> $curr->{type
},
98 name
=> $curr->{name
} },
100 $ds->sa->Add( "jobs", $curr );
108 Notes while trying to capture STDERR
110 The perl-module Filter::Handle lets you define a sub that will be
111 called each time anything is written to stderr. Unfortunately the
112 Filter::Handle tests in version 0.03 of the module eats up all
113 available memory and dies...
115 The perl-module Tie::STDERR allows you to do the same thing. See
116 test/tie-stderr for an example. However, Tie::STDERR will also catch
117 errors inside an eval, which is not desired. evals are used to try
118 things that may fail and still be ok, and we don't want to hear about
119 errors in these blocks. Sigh.
121 The only sane option is probably to wrap each job in an eval and catch
122 the output from the eval. Is this possible?