| 1 | #!/usr/bin/perl -w |
|---|
| 2 | |
|---|
| 3 | # Movable Type (r) Open Source (C) 2001-2008 Six Apart, Ltd. |
|---|
| 4 | # This program is distributed under the terms of the |
|---|
| 5 | # GNU General Public License, version 2. |
|---|
| 6 | # |
|---|
| 7 | # $Id$ |
|---|
| 8 | |
|---|
| 9 | use strict; |
|---|
| 10 | |
|---|
| 11 | use lib 'lib', '../lib'; |
|---|
| 12 | |
|---|
| 13 | my $daemonize = 0; |
|---|
| 14 | my $sleep = 5; |
|---|
| 15 | my $help = 0; |
|---|
| 16 | my $load = 10; |
|---|
| 17 | my $verbose = 0; |
|---|
| 18 | my $scoreboard; |
|---|
| 19 | my $randomize_jobs = 0; |
|---|
| 20 | my $trace_objects = 0; |
|---|
| 21 | |
|---|
| 22 | require Getopt::Long; |
|---|
| 23 | Getopt::Long::GetOptions( |
|---|
| 24 | "daemon" => \$daemonize, |
|---|
| 25 | "sleep=i" => \$sleep, |
|---|
| 26 | "load=i" => \$load, |
|---|
| 27 | "scoreboard=s" => \$scoreboard, |
|---|
| 28 | "randomly" => \$randomize_jobs, |
|---|
| 29 | "verbose" => \$verbose, |
|---|
| 30 | "leak" => \$trace_objects, |
|---|
| 31 | ); |
|---|
| 32 | |
|---|
| 33 | if ( $trace_objects ) { |
|---|
| 34 | require Devel::Leak::Object; |
|---|
| 35 | Devel::Leak::Object->import( qw{ GLOBAL_bless } ); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | my %cfg; |
|---|
| 39 | $cfg{verbose} = $verbose; |
|---|
| 40 | $cfg{scoreboard} = $scoreboard; |
|---|
| 41 | $cfg{prioritize} = 1; |
|---|
| 42 | $cfg{randomize} = $randomize_jobs; |
|---|
| 43 | |
|---|
| 44 | require MT::Bootstrap; |
|---|
| 45 | require MT; |
|---|
| 46 | |
|---|
| 47 | my $mt = MT->new() or die MT->errstr; |
|---|
| 48 | |
|---|
| 49 | $mt->{vtbl} = { }; |
|---|
| 50 | $mt->{is_admin} = 0; |
|---|
| 51 | $mt->{template_dir} = 'cms'; |
|---|
| 52 | $mt->{user_class} = 'MT::Author'; |
|---|
| 53 | $mt->{plugin_template_path} = 'tmpl'; |
|---|
| 54 | $mt->run_callbacks('init_app', $mt); |
|---|
| 55 | |
|---|
| 56 | my $client = eval { |
|---|
| 57 | require MT::TheSchwartz; |
|---|
| 58 | my $c = MT::TheSchwartz->new(%cfg); |
|---|
| 59 | no warnings 'once'; |
|---|
| 60 | $TheSchwartz::FIND_JOB_BATCH_SIZE = $load; |
|---|
| 61 | $c; |
|---|
| 62 | }; |
|---|
| 63 | if ((my $error = $@) && $verbose) { |
|---|
| 64 | print STDERR "Error initializing TheSchwartz: $error\n"; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | if ($daemonize && $client) { |
|---|
| 68 | $client->work_periodically($sleep); |
|---|
| 69 | } else { |
|---|
| 70 | # First, run periodic tasks |
|---|
| 71 | $mt->run_tasks(); |
|---|
| 72 | $client->work_until_done if $client; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | 1; |
|---|