#------------------------------------------------------------
# Copyright (C) 2009 RoyaltyShare, Inc.   All Rights Reserved
# $Id$
#------------------------------------------------------------
package RPS::CAMechanical::Job::RunMechanicals;

use strict;
use warnings;

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

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

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

use base 'RPS::CAMechanical::Job::Base';

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

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

    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/run_ca_mechanicals.pl -c $clientID -r $runID -V $logLevel";

    return $commandLine;
}

sub _defaultSubclass
{
    return 'CAMechanicalRunController';
}


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

    return 'run_controller';
}


sub _defaultPriority
{
    my $self = shift;
    my $clientID = Common::RSApp::GetClientID();
    my $count = Job::DB::Item::Job->GetActiveJobCount( $clientID, $self->_defaultSubclass() );
    
    
    return Job::Job::kPriorityNormal - $count * 50;
}


###
1;#
###

