#!/usr/bin/perl -w

# Copyright 2001-2007 Six Apart. This code cannot be redistributed without
# permission from www.movabletype.org.
#
# $Id: run-periodic-tasks 59399 2007-07-26 08:51:54Z fyoshimatsu $

use strict;

use lib 'lib', '../lib';
use MT::Bootstrap;
use MT;

my $mt = MT->new() or die MT->errstr;

require Getopt::Long;
my $daemonize = 0;
my $sleep     = 5;
my $help      = 0;
# my $sync      = 0;
# my $rsync_opt = '';
my $load      = 10;
my $verbose   = 0;

Getopt::Long::GetOptions(
    "daemon"      => \$daemonize,
    "sleep=i"     => \$sleep,
    # "help|?"      => \$help,
    # "throttle=i"  => \%throttle,
    # "worker=s"    => \$worker,
    # "sync"        => \$sync,
    # "to|target=s" => \@target,
    # "rsync=s"     => \$rsync_opt,
    "load=i"      => \$load,
    "verbose"     => \$verbose,
);

my %cfg;
$cfg{verbose} = $verbose;

require MT::TheSchwartz;
my $client = MT::TheSchwartz->new(%cfg);
no warnings 'once';
$TheSchwartz::FIND_JOB_BATCH_SIZE = $load;

if ($daemonize) {
    $client->work_periodically($sleep);
} else {
    # First, run periodic tasks
    $mt->run_tasks();
    $client->work_until_done;
}

1;
