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

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 Job::DB::Item::Job;

use base 'RPS::Mechanical::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/" . $self->_scriptName() . " -c $clientID -r $runID -V $logLevel";

    return $commandLine;
}

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

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;    #
###

