SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Run 24x7 job with COM library from excel

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Run 24x7 job with COM library from excel
Author Message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Run 24x7 job with COM library from excel Reply with quote
This is the EXIT function in excel(on my desktop) to start a 24x7 job on the master scheduler(located on a server).
The 24x7master runs in system tray mode.

The Job "24x7_Job12" is a JAL Skript on the 24x7 Master scheduler and it works manually.
It runs a RunAndWait method to trigger another file.

Code:
Sub Run24x7Job()

Dim obj As Object
Dim RetCode As Long
Dim RC As Integer

Set obj = CreateObject("24x7 Remote Control")

' open session
RC = obj.OpenSession("USER", "PWD", _
"WinSock", "ServerXX", "1096", "", False)

If RC <> 1 Then
     MsgBox obj.LastError
     'successfull !!
Else
     RetCode = obj.runJob("24x7_Job12", False)



Failed for me...!!

I Have 2 Problems with the method "runJob" in Object "obj":
obj.runJob("24x7_Job12", False):

1) obj.runJob("24x7_Job12", True)
A new instance ist not preferable and I can't wait, till the job is done.

2) obj.runJob("24x7_Job12", False)
The (JAL)"24x7_Job12" Job can't find the file in the RunAndWait(...) method.
The file to trigger, is located on the defined server, in Job "24x7_Job12"?

Code:

     If RetCode <> 1 Then
           MsgBox obj.LastError
     End If
     ' Close session
     RC = obj.CloseSession()
End If
' Destroy COM object and release all allocated resources
Set obj = Nothing
End Sub



THX for your support!!


Last edited by sts on Mon Mar 31, 2008 7:26 pm; edited 7 times in total
Mon Mar 31, 2008 11:57 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Quote:
RetCode = obj.runJob("24x7_Job12", False)
If RetCode <> 1 Then MsgBox obj.LastError ' Display error message

'Why does the 24x7 Master not find a specific file on a Server in Job "24x7_Job12" on the master scheduler?
'Job "24x7_Job12": 1) load a file... cant find the file 2) Starts a excel on a other server and loads a file



Please explain step by step what 24x7_Job12 is supposed to be doing. Is that a script type job or program type? If script, please provide the actual script.
Can you run this job manually on the mater scheduler computer? Does that work? Is the scheduler running in service mode or in the system tray?
Mon Mar 31, 2008 12:04 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Your messages are very confusing. If you continue editing the original post instead of replying to my messages, I will not be able to help you. Right now I have no idea where you are having problems. What file are you talking about? Is that a file not found error or login errors. If nether, then what?
Mon Mar 31, 2008 5:11 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Please do the following
1. Post the code of 24x7_Job12 job
2. Post the complete error message. You can copy and paste the error message text from schedule.log file

By the way, what's wrong with running the job detached? with this option, you don't need to wait for the job to complete and it could run just like any other job.

When replying to this message, please use Post Reply button, do NOT use the Edit button to modify your original post.
Mon Mar 31, 2008 8:40 pm View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
SysOp wrote:
Please do the following
1. Post the code of 24x7_Job12 job
2. Post the complete error message. You can copy and paste the error message text from schedule.log file


24x7_Job12:
Code:
// Kill App
Dim processID, number

ProcessGetID( "app.exe", processID)
ProcessKill processID

// restart App
RunAndWait "k:\sss\xxx.cmd", "",0, processID



24x7 LOG:
01.04.2008 14:33:14 0 239 0 VBV_M_A_RESTART_QX Remote job started.
01.04.2008 14:33:14 0 239 0 VBV_M_A_RESTART_QX Job started.
01.04.2008 14:33:14 2 239 0 VBV_M_A_RESTART_QX An error occurred while executing automation script: Line 5: Process not found.
01.04.2008 14:33:14 2 239 0 VBV_M_A_RESTART_QX Remote job execution error. Exit code: -1. An error occurred while executing automation script: Line 5:
Process not found.

SysOp wrote:
By the way, what's wrong with running the job detached? with this option, you don't need to wait for the job to complete and it could run just like any other job.


I want to start another job in the same process queue. You mean with detached a new instance?
Tue Apr 01, 2008 8:47 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
It says "process" not found, which means that "app.exe" is not running or not visible to the scheduler when you execute this job remotely. I don't believe this is an issue related to the remote control or COM interface. Please double-check the referenced process is still running when you trigger the job.

Jobs forcedly triggered for immediate run, always run out of queue. One way to get a job starting in a queue, is to set the job schedule to file-watch "when certain file found" and create that file remotely using the available COM interface. For that you can use RunScript to execute an add-hoc script, for example,

RetCode = obj.RunScript( "FileSave ""C:\some_file"", ""any text"" ")

The job should find the created file in a few seconds or minutes (depending on how often it is set to check for this file) and it should then go to the associated job queue.

By the way, you might have syntax errors in your job script, you likely forgot about special use of backslash characters

RunAndWait "k:\sss\xxx.cmd", "",0, processID
should be
RunAndWait "k:\\sss\\xxx.cmd", "",0, processID
Tue Apr 01, 2008 11:33 am View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
It says "process" not found .. --> oversight this at the first call "ProcessGetID( "app.exe", processID)"

The main problem is that 24x7 dont come back with the "processEnd" message when a process takes longer than ca. 1:00 hour.
Because of this I want to start the Job (runtime >1 hour mostly excel files) with the "runJob" method in Excel.

1) obj.runJob("24x7_Job12", True)
A new instance ist not possible and not preferable, cause the port is in use.

2) obj.runJob("24x7_Job12", False)
The open session method has opened a session to the Main 24x7Scheduler. The Job "24x7_Job12" does a connection to SERVER1(Settings in Job (JAL)). This connection could not be established --> process not found.

I thik the problem something with OpenSession(Settings:Main24x7Scheduler_Server) and SERVER1(Settings) in job "24x7_Job12"
Is there an other solution?

3) Your solution with "file-watch" (not preferable)
That is my last option. How can I integrate "file-watch"?

thank you...
Fri Apr 04, 2008 8:39 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Quote:
The main problem is that 24x7 dont come back with the "processEnd" message when a process takes longer than ca. 1:00 hour.


That's because your session timeouts before the job is completed. Why do you need to wait for that process? why not use Run instead of RunAndWait and let it go?

RunAndWait "k:\sss\xxx.cmd", "",0, processID

replace that with

RunAndWait "k:\sss\xxx.cmd", "", processID

This will solve all your other issues. No need to wait, no need to run job in a separate process, not need to trigger it asynchronously. Right?
Fri Apr 04, 2008 11:07 am View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
SysOp wrote:
Quote:
The main problem is that 24x7 dont come back with the "processEnd" message when a process takes longer than ca. 1:00 hour.


That's because your session timeouts before the job is completed.


Why does the session timeouts? How can I prevent this?

Quote:
Why do you need to wait for that process? why not use Run instead of RunAndWait and let it go?


Cause the process(exe/Excel/bat......) generate some files that be used to the next task. So I need a message when job is done.

Quote:
RunAndWait "k:\sss\xxx.cmd", "",0, processID

replace that with

RunAndWait "k:\sss\xxx.cmd", "", processID

This will solve all your other issues. No need to wait, no need to run job in a separate process, not need to trigger it asynchronously. Right?


No....

Code:
// Kill App
Dim processID, number

ProcessGetID( "app.exe", processID)
ProcessKill processID

// restart App
RunAndWait "k:\sss\xxx.cmd", "",0, processID


this task runs every day since 1 year. ("k:\sss\xxx.cmd" is working, but i know the problems....sometimes)
Mon Apr 07, 2008 6:45 am View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
The main problem is that 24x7 dont come back with the "processEnd" message when a process takes longer than ca. 1:00 hour.

My Tasks:

1) (JAL)
RunAndWait ---> not stable for jobs > 1 Hour

2) I want to start the Job (runtime >1 hour mostly excel files) with the "runJob" method in my "Run24x7Job" function in Excel.

a)obj.runJob("24x7_Job12", True)
A new instance ist not possible and not preferable, cause the port is in use.

b)obj.runJob("24x7_Job12", False)
The open session method has opened a session to the Main 24x7SchedulerServer. The Job "24x7_Job12" should do a connection to SERVER1(Settings in Job (JAL)). This connection could not be established --> process not found.

That means thet the 24x7 scheduler cant connect to SERVER1(Settings in Job "24x7_Job12"(JAL))

If I connect to a job(24x7_Job12) with the open session method, the Server Settings in this job(24x7_Job12) will be ignored?
If this ist true. How can I schedule the tasks without the "file-watch" "solution".
Mon Apr 07, 2008 7:55 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Well. the issue is not with RunAndWait - the issue is wityh oyur remote session timing out after an hour, before a job gets chance to complete. This happens because the remote session is not doing anything for a long time and the socket gets closed by the system. It is actually Windows that closes the socket, not 24x7. 60 minutes is a default timeout to stale network connections.

I can suggest a different solution, use Run to launch the process and then periodically check if the process is still alive. If you do it periodically, perhaps once every few minute, the remote session will not stale and will not timeout after an hour.

The tricky part here is checking for the remote process if it is still alive. Here is how you can do that


1. In the replace RunAndWait with Run command.
2. In the Excel macro do the following after you launch the job using RunJob

Code:
Dim RetCode, Output, FoundPos
FoundPos = 1

Do While FoundPos > 0
   RetCode = obj.UtilRunScript( "ProcessList Output" )

   If RetCode <> 1 Then
      ' handle error
      ' . . .
   Else
     ' check if process in then list
     Pos(Output, "WHATEVER.EXE", FoundPos)
     If Pos > 0 then Script.Wait(60000) ' wait 1 minute and then try again
   End If
Loop

'. . . process completed

Mon Apr 07, 2008 10:21 am View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
Thanks for your input. I can use this later, but not in this case.
By the way.
Pos(Output, "WHATEVER.EXE", FoundPos)
Is not a method from the COM Object. My excel cant find this method.

The Problem is that the job "24x7_Job12" cant find the app.exe process, cant kill it and cant find the file in the Run or RunAndWait statement. I think that is caused by the opensession method on the Excel makro. The job "24x7_Job12" setting to the Server, where the app.exe and the xxx.cmd are located, will be ignored. Ist that right?

Code:

// Kill App
Dim processID, number

ProcessGetID( "app.exe", processID)
ProcessKill processID

// restart App
RunAndWait "k:\\sss\\xxx.cmd", "",0, processID


ProcessGetID( "app.exe", processID) ---> cant kill process. An error occurred while executing automation script: Line 5: Process not found. Remote job execution error. Exit code: -1. An error occurred while executing automation script: Line 5:Process not found.

So it would be nice to have a excel method where I can start a 24x7 Job that is considering the server settings in the job.
Tue Apr 08, 2008 8:51 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
This is not an API call. The process list is returned to the caller, and the value can be searched in that script. For example, you can use standard InStr function.

If you use the suggested method you can always verify in the Excel file if app.exe is running or not. I bet you are looking in a wrong place. When you get the remote process list in Excel, you will see that app.exe is named differently or not running.
Tue Apr 08, 2008 11:04 am View user's profile Send private message
sts



Joined: 31 Mar 2008
Posts: 7
Country: Switzerland

Post Reply with quote
Quote:
This is not an API call. The process list is returned to the caller, and the value can be searched in that script. For example, you can use standard InStr function.

Ok, but "Pos(Output, "WHATEVER.EXE", FoundPos)" doesn't work "and this is not my main problem". I will try "InStr". ... Thanks


MY MAIN PROBLEM
Procedure:
In order to use the COM interface you have to do a open session statement to the MasterScheduler(ServerXX).

1) RC = obj.OpenSession("USER", "PWD", _"WinSock", "ServerXX", "1096", "", False) (server settings to master scheduler "ServerXX")
2) obj.runJob("24x7_Job12", True)
3) "24x7_Job12" (Job Properties: 24x7 Agent / Host: SERVER1)
The process(process is running) on SERVER1 could not be found. "An error occurred while executing automation script: Line 5: Process not found."
The Problem is that the job "24x7_Job12" cant find the app.exe process, cant kill it and cant find the file in the Run or RunAndWait statement.

By the way. I need to schedule the jobs(kill, run etc.) from the master scheduler on "ServerXX", so that the next job (a.e."24x7_Job13") is triggered by "24x7_Job12"and runs in the defined queue.

As example a other job without process kill:

Code:
Dim fileName, string
Dim checkString, string
Dim buffer, string
Dim position, number
Dim file_found, boolean
Dim err_found, boolean

FileFindFirst "K:\\PPP\\DDD\\Someth*", fileName, file_found
Concat ""K:\\PPP\\DDD\\", fileName, fileName

Set checkString, "<td>in error</td>"

// Load the log file into memory
FileReadAll (fileName , buffer)

// Search for checkString
Pos (buffer, checkString , 1, position)

// If error found, notify system administrator
IsGreater (position, 0, err_found)
If (err_found, NOTIFY, END)

NOTIFY:
// Raise Error to stop process
RaiseError "Error in XXX"

END:
// DONE


This leads to: Line 15: File not found. Remote job execution error. Exit code: -1. An error occurred while executing automation script: Line 15: File not found.

Same Problem:
The Problem is that the job "24x7_Job12" cant find the app.exe process, cant kill it and cant find the file in the statement. I think that is caused by the opensession method in the Excel makro. The job "24x7_Job12" setting to the Server, where the file "K:\\PPP\\DDD\\Someth*" is located, will be ignored. Is that right?

-------------------------------------

I tryed a job that is running on the ServerXX (opensession connecting to the local host)
"RC = obj.OpenSession("USER", "PWD", _"WinSock", "ServerXX", "1096", "", False) (server settings to master scheduler "ServerXX")

The job was sucsessfull, but the next job, witch is set in the job properties(Run this job2 if job1 is finished) is not starting. Why?
By the way. I need to schedule the jobs(kill, run etc.) from the master scheduler on "ServerXX", so that the next job (a.e."24x7_Job13") is triggered by "24x7_Job12"and runs in the defined queue.

And I do the whole thing cause RunAndWait isn't stable:
Quote:
Windows closes the socket after 60 minutes. It's a default timeout to stale network connections.


Is there a way to prevernt this?

I know i'm little confusing, but I think now it should be clear. THANKS!!!!!!!!
Wed Apr 09, 2008 8:53 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7949

Post Reply with quote
Quote:
The process(process is running) on SERVER1 could not be found. "An error occurred while executing automation script: Line 5: Process not found."
The Problem is that the job "24x7_Job12" cant find the app.exe process, cant kill it and cant find the file in the Run or RunAndWait statement.

Quote:
This leads to: Line 15: File not found. Remote job execution error. Exit code: -1. An error occurred while executing automation script: Line 15: File not found.


Let's assume for the moment, that you are right when saying the app.exe is running and the other file is actually there. Let's also assume that when you run these jobs locally on the scheduler system, both job 12 and 13 behave as expected. Let's also assume that the scheduler is running in graphical mode both when you test-run jobs directly on the server and when you run them remotely via COM interface (this is important because if you run it as a service, the account may have different permissions). If any of these assumptions are wrong, please let us know, because this is not what you have described here.

Having said that let's check what could be causing the scheduler not to find them. There is a very simple way to check that. Just create a test job to return a list of running processes, see my implementation suggestions in the previous replies for details, and take a look if the process in question is listed in the result. Create another test job to return list of files in the directory where you are looking for the file and take a look at that result too. You can easily figure out whether the returned matches what you expect and whether the process and file are actually there.

Quote:
Windows closes the socket after 60 minutes. It's a default timeout to stale network connections.
Is there a way to prevernt this?


The solution is not to design remote jobs to wait for a long long time. Make them start something and then periodically come back and check if the started processing is complete. This is of course a bit more complicated that run-and-wait approach, but it does help to workaround the timeout issue.
Wed Apr 09, 2008 11:10 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.