Changeset 3886 for trunk/tools
- Timestamp:
- 06/19/09 04:11:07 (5 months ago)
- Files:
-
- 1 modified
-
trunk/tools/run-periodic-tasks (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/run-periodic-tasks
r3531 r3886 9 9 use strict; 10 10 11 use lib 'lib', '../lib' ;11 use lib 'lib', '../lib', 'extlib', '../extlib'; 12 12 13 13 my $daemonize = 0; … … 18 18 my $scoreboard; 19 19 my $randomize_jobs = 0; 20 my $trace_objects = 0;20 my $trace_objects = 0; 21 21 22 22 require Getopt::Long; … … 30 30 "leak" => \$trace_objects, 31 31 ); 32 require MT::TheSchwartz; 32 33 33 if ( $trace_objects) {34 if ($trace_objects) { 34 35 require Devel::Leak::Object; 35 Devel::Leak::Object->import( qw{ GLOBAL_bless });36 Devel::Leak::Object->import(qw{ GLOBAL_bless }); 36 37 } 37 38 39 my $proc_process_table = eval { 40 require Proc::ProcessTable; 41 1; 42 }; 43 44 $@ = undef; 45 38 46 my %cfg; 39 $cfg{verbose} = $verbose;47 $cfg{verbose} = $verbose; 40 48 $cfg{scoreboard} = $scoreboard; 41 49 $cfg{prioritize} = 1; 42 $cfg{randomize} = $randomize_jobs;50 $cfg{randomize} = $randomize_jobs; 43 51 44 52 require MT::Bootstrap; … … 46 54 47 55 my $mt = MT->new() or die MT->errstr; 56 if ( defined(MT->config('RPTProcessCap')) && $proc_process_table ) { 57 my $t = new Proc::ProcessTable; 58 my $rpt_count; 59 foreach my $p ( @{ $t->table } ) { 60 my $cmd = $p->cmndline; 61 if ( $cmd =~ /^perl/ && $cmd =~ /run-periodic-tasks/ ) { 62 $rpt_count += 1; 63 } 64 } 65 if ( $rpt_count > MT->config('RPTProcessCap') ) { 66 $rpt_count = $rpt_count - 1; # Don't report this RPT 67 die "$rpt_count processes already running; cancelling RPT launch\n"; 68 } 69 } 48 70 49 $mt->{vtbl} = { }; 50 $mt->{is_admin} = 0; 51 $mt->{template_dir} = 'cms'; 52 $mt->{user_class} = 'MT::Author'; 71 if ( MT->config('RPTFreeMemoryLimit') ) { 72 my $limit = MT->config('RPTFreeMemoryLimit'); 73 if ( $limit and ! MT::TheSchwartz::_has_enough_swap($limit) ) { 74 die 75 "Free memory below RPT limit; cancelling RPT launch\n"; 76 } 77 } 78 if ( MT->config('RPTFreeSwapLimit') ) { 79 my $swaplimit = MT->config('RPTSwapMemoryLimit'); 80 if ( $swaplimit and ! MT::TheSchwartz::_has_enough_swap($swaplimit) ) { 81 die 82 "Free swap memory below RPT limit; cancelling RPT launch\n"; 83 } 84 } 85 86 $mt->{vtbl} = {}; 87 $mt->{is_admin} = 0; 88 $mt->{template_dir} = 'cms'; 89 $mt->{user_class} = 'MT::Author'; 53 90 $mt->{plugin_template_path} = 'tmpl'; 54 $mt->run_callbacks( 'init_app', $mt);91 $mt->run_callbacks( 'init_app', $mt ); 55 92 56 93 my $client = eval { … … 61 98 $c; 62 99 }; 63 if ( (my $error = $@) && $verbose) {100 if ( ( my $error = $@ ) && $verbose ) { 64 101 print STDERR "Error initializing TheSchwartz: $error\n"; 65 102 } 66 103 67 if ( $daemonize && $client) {104 if ( $daemonize && $client ) { 68 105 $client->work_periodically($sleep); 69 } else { 106 } 107 else { 108 70 109 # First, run periodic tasks 71 110 $mt->run_tasks();
