root/branches/release-38/tools/run-periodic-tasks @ 2272

Revision 2272, 1.4 kB (checked in by bchoate, 19 months ago)

Added 'randomly' flag to control whether jobs are shuffled when selecting work to do. Default does not randomize jobs within batch selected.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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
9use strict;
10
11use lib 'lib', '../lib';
12use MT::Bootstrap;
13use MT;
14
15my $mt = MT->new() or die MT->errstr;
16
17$mt->{vtbl} = { };
18$mt->{is_admin} = 0;
19$mt->{template_dir} = 'cms';
20$mt->{user_class} = 'MT::Author';
21$mt->{plugin_template_path} = 'tmpl';
22$mt->run_callbacks('init_app', $mt);
23
24require Getopt::Long;
25my $daemonize = 0;
26my $sleep     = 5;
27my $help      = 0;
28my $load      = 10;
29my $verbose   = 0;
30my $scoreboard;
31my $randomize_jobs = 0;
32
33Getopt::Long::GetOptions(
34    "daemon"       => \$daemonize,
35    "sleep=i"      => \$sleep,
36    "load=i"       => \$load,
37    "scoreboard=s" => \$scoreboard,
38    "randomly"     => \$randomize_jobs,
39    "verbose"      => \$verbose,
40);
41
42my %cfg;
43$cfg{verbose} = $verbose;
44$cfg{scoreboard} = $scoreboard;
45$cfg{prioritize} = 1;
46$cfg{randomize} = $randomize_jobs;
47
48my $client = eval {
49    require MT::TheSchwartz;
50    my $c = MT::TheSchwartz->new(%cfg);
51    no warnings 'once';
52    $TheSchwartz::FIND_JOB_BATCH_SIZE = $load;
53    $c;
54};
55if ((my $error = $@) && $verbose) {
56    print STDERR "Error initializing TheSchwartz: $error\n";
57}
58
59if ($daemonize && $client) {
60    $client->work_periodically($sleep);
61} else {
62    # First, run periodic tasks
63    $mt->run_tasks();
64    $client->work_until_done if $client;
65}
66
671;
Note: See TracBrowser for help on using the browser.