Siebel Analytics Scheduler Guide > Configuring Siebel Analytics Scheduler Job Scripts >

Job Manager Script for Cache Clearance


Siebel Analytics Scheduler can be used for general purpose scripts that extend the functionality of Siebel Analytics.

The script purgeSASCache.js is used to periodically purge all of the cache from the Siebel Analytics Server:

/////////////////////////////////////////////////////////
// purgeSASCache.js
//
// Purges the cache on SAS.
// Parameter(0) - The user name to pass in to NQCMD.
// Parameter(1) - The password for the aforementioned user.
/////////////////////////////////////////////////////////

// The full path to nqcmd.exe
var nqCmd = "D:\\SiebelAnalytics\\Bin\\nqcmd.exe";

// The data source name
var dsn = "Analytics Web";

// The user to execute the queries
var user = Parameter(0);

// The password of the aforementioned user
var pswd = Parameter(1);

// The ODBC procedure call for purging the cache
var sqlStatement = "{call SAPurgeAllCache()};";

//////////////////////////////////////////////////////////
// Returns a string from the file name
//////////////////////////////////////////////////////////

function GetOutput(fso, fileName)
{
    var outStream = fso.OpenTextFile(fileName, 1);
    var output = outStream.ReadAll();
    outStream.Close();
    return output;
}

//////////////////////////////////////////////////////////
// Get WshShell object and run nqCmd. Capture the output
// so that we can handle erroneous conditions.

var wshShell = new ActiveXObject("WScript.Shell");

// Create a temp file to input the SQL statement.

var fso = new ActiveXObject("Scripting.FileSystemObject");

var tempFolder = fso.GetSpecialFolder(2);
var tempInFileName = fso.GetTempName();
var tempOutFileName = fso.GetTempName();
tempInFileName = tempFolder + "\\" + tempInFileName;
tempOutFileName = tempFolder + "\\" + tempOutFileName;
var tempInFile = fso.CreateTextFile(tempInFileName, true);
tempInFile.WriteLine(sqlStatement);
tempInFile.Close();

try
{

    // execute
    var dosCmd = nqCmd + " -d \"" + dsn + "\" -u \"" + user
        + "\" -p \"" + pswd + "\" -s \"" + tempInFileName + "\"" +
        " -o \"" + tempOutFileName + "\"";

    wshShell.Run(dosCmd, 0, true);

    var output = GetOutput(fso, tempOutFileName);

    // Remove the temp files
    fso.DeleteFile(tempInFileName);
    if (fso.FileExists(tempOutFileName)) {
        fso.DeleteFile(tempOutFileName);

}

    // Check the output for any errors
    if (output.indexOf("Processed: 1 queries") == -1) {
        ExitCode = -1;
        Message = output;
    }

    else if (output.indexOf("Encountered") != -1) {
        ExitCode = -2;
        Message = output;
    }
    else {
        ExitCode = 0;
    }
} catch (e) {
    if (fso.FileExists(tempInFileName)) {
        fso.DeleteFile(tempInFileName);
    }

    if (fso.FileExists(tempOutFileName)) {
        fso.DeleteFile(tempOutFileName);
    }
    throw e;

}

Siebel Analytics Scheduler Guide