#------------------------------------------------------------
# Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::Mechanical::Job::CreateStatement;

use strict;
use warnings;

use Sys::Hostname;

use lib '/app/tools/common/lib';
use Common::Assert;

use lib '/app/tools/rps/lib';
use RPS::Config;

use lib '/app/tools/job/lib';
use Job::Job;

use base 'RPS::Mechanical::Job::ChildBase';


sub _generateCommandLine
{
    my ($self) = @_;

    my $statementID = $self->getCommandLineArg('statementID');
    assert($statementID);

    my $clientID = $self->clientID();
    assert($clientID);

    my $logLevel = $self->getCommandLineArg('logLevel');
    $logLevel = 1 unless $logLevel;

    # !!! Use the 'config' system to get the path to the royalty scripts.
    #
    my $rpsConfig = RPS::Config->new();
    my $scriptPath = $rpsConfig->get('royalty_script_dir');


    # !!! Note that this is a linux-only command line.
    # !!! If we end up wanting to run these on windows <shudder>, we'd have
    # !!! to create a 'Win32' subclass and override this method.
    # !!! Actually, we'd need to create a 'linux' subclass as well.
    #
    my $commandLine = "nice $scriptPath/" . $self->_scriptName() . " -c $clientID -s $statementID -V $logLevel";

    return $commandLine;
}

sub _scriptName         { assert(0, 'override this'); }
sub _defaultSubclass    { assert(0, 'override this'); }


sub _defaultClass       { return 'CreateStatement'; }


sub _defaultLogFile
{
    my ($self) = @_;

    my $statementID = $self->getCommandLineArg('statementID');
    assert($statementID);

    return "statement_$statementID";

}

# Going to introduce some randomness into the priority values
# This is to avoid having all the jobs for a single run stuck together
# in a single clump - Otherwise, huge runs will prevent smaller runs from 
# going until the big run is done, which is not what I want.
#
sub _defaultPriority
{
    return (Job::Job::kPriorityNormal + int( rand(1000) ));
}


###
1;#
###

