I have achieved the desired by modifiying the script in an exe (TOM apis) file and then calling it from a .bat file (as suggested by Bart) in the following way: The only thing it uses TDSE object whcih seems to be causing some meamory leckage issues (though we are releasing the TDSE object properly) in our environment. But it checks the queue and then retsrt services if nothing in queue except '6' status (Success).
using System.Text;
using Tridion.ContentManager.Interop.TDSDefines;
using Tridion.ContentManager.Interop.TDS;
using System.Runtime.InteropServices;
namespace PublishingQueueMonitor
{
class PublishingQueueStatus
{
static int Main(string[] args)
{
int active = 0;
int successCount = 0;
TDSE tdse = new TDSE();
XmlDocument itemsXmlDoc = new XmlDocument();
tdse.Initialize();
ManagementInfo managementInfo = tdse.GetManagementInfo();
ListRowFilter filter = tdse.CreateListRowFilter();
//filter.SetCondition("InfoType", "1");
String itemsXml = managementInfo.GetListPublishTransactions(filter); //for Publish Trasactions
//String itemsXMLNew=managementInfo.GetListPublishQueue(filter); //for publishing queue items
Marshal.ReleaseComObject(tdse);
itemsXmlDoc.LoadXml(itemsXml);
XmlElement root = itemsXmlDoc.DocumentElement;
if (root.ChildNodes.Count>0)
{
foreach (XmlNode node in root.ChildNodes)
{
int state = Convert.ToInt32(node.Attributes["State"].Value);
DateTime stateChangeDate = Convert.ToDateTime(node.Attributes["StateChangeDate"].Value).Date;
if ((state != 6) && (stateChangeDate >= DateTime.Now.AddDays(-2))) //6 is Success and date is publish state change date
{
active++;
}
else if (state == 6)
{
successCount++;
}
}
}
Console.WriteLine("No of Ongoing Publishing Items in Queue: {0}", active);
Console.WriteLine("No of Successfully published Items in Queue: {0}", successCount);
Console.Read();
return active;
}
}
}
The .bat script as follows: (suggested by Mr. Bart)
@ECHO OFF
PublishingQueueMonitor.exe
IF NOT %ERRORLEVEL% == 0 GOTO error
ECHO Publish Queue is empty.
REM restart publisher
:: set folder path
set dump_path=D:\Tridion\log\
:: set min age of files and folders to delete
set max_days=0
net stop "Tridion Content Manager Publisher"
:: remove files/subdirectories from %dump_path%
forfiles -p %dump_path% -s -m *.* -d -%max_days% -c "cmd /c del /q @path"
:: remove empty directories
dir /ad /b /s %dump_path% |sort /r >tmp.tmp
for /f "delims=" %%a in (tmp.tmp) do rd "%%a" 2>nul
del tmp.tmp
net start "Tridion Content Manager Publisher"
GOTO end
:error
ECHO %ERRORLEVEL% active Publish Transactions in Queue.
Please let me know your concerns. Thanks again for the indication