use IO::File;
use DXLog;
+use Mojo::IOLoop::Subprocess;
+
use strict;
use vars qw{@crontab @lcrontab @scrontab $mtime $lasttime $lastmin};
my $line = 0;
my @out;
- dbg("cron: reading $fn\n") if isdbg('cron');
+ dbg("DXCron::cread reading $fn\n") if isdbg('cron');
open($fh, $fn) or confess("cron: can't open $fn $!");
while (<$fh>) {
$line++;
if (!$err) {
$ref->{cmd} = $cmd;
push @out, $ref;
- dbg("cron: adding $_\n") if isdbg('cron');
+ dbg("DXCron::cread: adding $_\n") if isdbg('cron');
} else {
- dbg("cron: error on line $line '$_'\n") if isdbg('cron');
+ dbg("DXCron::cread: error on line $line '$_'\n") if isdbg('cron');
}
}
close($fh);
{
my $line = shift;
- my $fc = Mojo::IOLoop::ForkCall->new;
+ dbg("DXCron::spawn: $line") if isdbg("cron");
+ my $fc = Mojo::IOLoop::Subprocess->new();
$fc->run(
sub {my @res = `$line`; return @res},
- [],
sub {
my ($fc, $err, @res) = @_;
- if (defined $err) {
+ if ($err) {
my $s = "DXCron::spawn: error $err";
dbg($s);
return;
);
}
+sub spawn_cmd
+{
+ my $line = shift;
+
+ dbg("DXCron::spawn_cmd run: $line") if isdbg('cron');
+ my $fc = Mojo::IOLoop::Subprocess->new();
+ $fc->run(
+ sub {
+ $main::me->{_nospawn} = 1;
+ my @res = $main::me->run_cmd($line);
+ delete $main::me->{_nospawn};
+ return @res;
+ },
+ sub {
+ my ($fc, $err, @res) = @_;
+ if ($err) {
+ my $s = "DXCron::spawn_cmd: error $err";
+ dbg($s);
+ }
+ for (@res) {
+ chomp;
+ dbg("DXCron::spawn_cmd: $_") if isdbg("cron");
+ }
+ }
+ );
+}
+
# do an rcmd to another cluster from the crontab
sub rcmd
{
sub run_cmd
{
my $line = shift;
- my @in = DXCommandmode::run_cmd($main::me, $line);
- dbg("cmd run: $line") if isdbg('cron');
+ my @in = $main::me->run_cmd($line);
+ dbg("DXCron::run_cmd: $line") if isdbg('cron');
for (@in) {
s/\s*$//og;
- dbg("cmd out: $_") if isdbg('cron');
+ dbg("DXCron::cmd out: $_") if isdbg('cron');
}
}
+
1;
__END__