X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXCron.pm;h=c011d7b3d3e3df0740bfbdc3662edd6646b95d30;hb=refs%2Fheads%2Fnew-spawn;hp=757ec61cd640756b6b6d7587c1e62f06143e81bc;hpb=8634689f5dcb3d2ab2b748aeb9d8401a0889a443;p=spider.git diff --git a/perl/DXCron.pm b/perl/DXCron.pm index 757ec61c..c011d7b3 100644 --- a/perl/DXCron.pm +++ b/perl/DXCron.pm @@ -15,6 +15,8 @@ use DXDebug; use IO::File; use DXLog; +use Mojo::IOLoop::Subprocess; + use strict; use vars qw{@crontab @lcrontab @scrontab $mtime $lasttime $lastmin}; @@ -60,7 +62,7 @@ sub cread 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++; @@ -79,9 +81,9 @@ sub cread 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); @@ -244,13 +246,13 @@ sub spawn { 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; @@ -267,20 +269,24 @@ sub spawn_cmd { my $line = shift; - dbg("spawn_cmd run: $line") if isdbg('cron'); - my $fc = Mojo::IOLoop::ForkCall->new; + dbg("DXCron::spawn_cmd run: $line") if isdbg('cron'); + my $fc = Mojo::IOLoop::Subprocess->new(); $fc->run( - sub {my @res = DXCommandmode::run_cmd($main::me, $line); return @res}, - [], + sub { + $main::me->{_nospawn} = 1; + my @res = $main::me->run_cmd($line); + delete $main::me->{_nospawn}; + return @res; + }, sub { my ($fc, $err, @res) = @_; - if (defined $err) { - my $s = "spawn_cmd: error $err"; + if ($err) { + my $s = "DXCron::spawn_cmd: error $err"; dbg($s); } for (@res) { chomp; - dbg("spawn_cmd: $_") if isdbg("cron"); + dbg("DXCron::spawn_cmd: $_") if isdbg("cron"); } } ); @@ -303,12 +309,13 @@ 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__