Committer: afedorov
LJSUP-10881: Add new option "only once and exit" for workersU trunk/cgi-bin/LJ/NewWorker/TheSchwartz.pm U trunk/cgi-bin/LJ/NewWorker.pm
Modified: trunk/cgi-bin/LJ/NewWorker/TheSchwartz.pm =================================================================== --- trunk/cgi-bin/LJ/NewWorker/TheSchwartz.pm 2011-12-23 11:08:52 UTC (rev 20851) +++ trunk/cgi-bin/LJ/NewWorker/TheSchwartz.pm 2011-12-23 11:58:36 UTC (rev 20852) @@ -55,6 +55,8 @@ sub run { my $class = shift; + my $opts = shift; + my $sleep = 0; $verbose = $class->verbose; @@ -90,6 +92,7 @@ LJ::end_request(); }; warn $@ if $@; + last if $opts->{'run_once'}; } } Modified: trunk/cgi-bin/LJ/NewWorker.pm =================================================================== --- trunk/cgi-bin/LJ/NewWorker.pm 2011-12-23 11:08:52 UTC (rev 20851) +++ trunk/cgi-bin/LJ/NewWorker.pm 2011-12-23 11:58:36 UTC (rev 20852) @@ -66,6 +66,7 @@ "-d | --daemon n start as daemon\n" . "-v | --verbose increase verbose level\n" . "-m | --memory n set memory limit to n megabytes\n", + "-o | --once run only once and exit", $self->help(), "\n"; exit 0; @@ -83,12 +84,14 @@ $0 =~ m|([^/]*)$|; $name = $1; + my $run_once; # Get command line die "Wrong options" unless GetOptions( 'daemons|d=i' => \$quantity, 'verbose|v+' => \$verbose, 'help|h' => sub { $self->print_help() }, 'memory|m=i' => sub { $self->set_memory_limit(1024 * 1024 * $_[1]) }, + 'once' => \$run_once, $self->options() ); @@ -106,6 +109,8 @@ my $bin = "$ljhome/bin/worker"; die "LJHOME/bin/worker directory doesn't exist" unless -d $bin; die "piddir $piddir doesn't exist" unless -d $piddir; + + my $opts = { run_once => $run_once }; # Start if ($quantity) { @@ -155,7 +160,7 @@ $self->catch_output(); # And finally go to work. - $self->run(); + $self->run($opts); # Before exit from child, call at_exit() and remove pid file $self->at_exit(); @@ -204,7 +209,7 @@ $self->after_fork(); # Run at console - $self->run(); + $self->run($opts); # Before exit, call at_exit() $self->at_exit();