Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Prg does not wait for method to finish
Message
From
14/07/2006 16:23:30
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Title:
Prg does not wait for method to finish
Miscellaneous
Thread ID:
01136561
Message ID:
01136561
Views:
55
Hi All,

I'm working on a table-driven nighttime job scheduler to replace my current way of doing things. Currently, I have a master prg that calls each job prg in order and creates log info for it. I'm wanting to better control the scheduled jobs this way, without changing a prg all the time. I can change the way these jobs run by editing the table entries to change the running order, enable and disable jobs, add new jobs and schedule them, etc.


Tables:

Table Nightcontrol - houses the information on each job(prg):

id - autoincrement I
job name - a 15 character short name.
joborder - the order the job runs in, in case I want to reorder them due to dependencies etc.
prgname - the fully pathed name of the prg to be run.
jobenabled - logical to enable or disable a job
laststart - datetime the job was last started.
lastend - datetime the job last ended.

Table Nightlog - contains log info for each nightly run.

id - autioincrement I
start_date - datetime nightly run started
end_date - datetime all jobs completed
detail - memo holding detailed job history, errors encountered for each etc.


I have created a new program that will scan through the nightcontrol table in joborder sequence and run those jobs found to be enabled, and log their progress. I created a class called MyRunner based on Session that is used to run each program. I wanted them to have their own data sessions to prevent them from stepping on each others' toes, or interfering with each other. the class runs the indicated prg in a try .. catch and handles its own errors. it's supposed to log the error , clean up after itself and go away so as to not stop the next job, if possible.


I'm getting error 1951 in my job log:


All input and comments are appreciated. I think I know what this may be, some of the prgs may have 'CLEAR ALL' in them somewhere. I'll check that out. in any case, any suggestions for improvements or danger warnings will be welcomed.

Error information:
: [c:\nightly\progs\roll forward due dates.prg]

Error#: 1951Line #: 3: Cannot clear the object MYRUNNER because it is in use.
07/14/2006 02:30:38 PM
Some Code:
&& JWN - 07/14/06 02:49:41 PM
&& Run Scheduled Jobs
Close Tables All
Close Databases All
Clear All
Release All
Set Classlib To
Set Deleted On
Set Exclusive Off
Set Safety Off
ON ERROR 
Local lnId, lnNumrecs, lcAppToRun, llJobEnabled
Use l:\Shared\nightcontrol In 0 Order joborder
cAppToRun = ''

DO CreateNightLogEntry


Select nightcontrol
lnNumrecs  = Reccount()
Scan
	lnId = nightcontrol.Id
	llJobEnabled = nightcontrol.jobenabled
	lcAppToRun = Alltrim(nightcontrol.prgname)
	If llJobEnabled
		LogProgress(CHR(13)+[: ]+lcAppToRun+CHR(13))
		SELECT nightcontrol
		REPLACE laststart WITH DATETIME()
		oRunner = Createobject("myrunner")
		oRunner.RunProgram(lcAppToRun)
		Release oRunner
		SELECT nightcontrol
		REPLACE lastend WITH DATETIME()
		LogProgress( Alltrim( Ttoc( Datetime() ) ) + Chr( 13 ) )
	Endif
Endscan
Do MyCleanup



&& Procedures

PROCEDURE CreateNightLogEntry
Use l:\shared\nightlog In 0
Select nightlog
Append Blank
TMPDATE = Datetime()
Replace start_date With TMPDATE
Use

ENDPROC 

Function LogProgress( cStr )
	OpenLog()
	Select nightlog
	Go Bottom
	Replace Detail With Detail + cStr
Endfunc



*!* Function: OpenLog()
*!* Description: Opens the log file
*!* Date: 07/16/01
Function OpenLog()
	Open Database l:\Database\Shared
	If !Used( "nightlog" )
		Use nightlog In 0 Order Id
	Endif
Endfunc



Procedure MyCleanup
	If Used('nightcontrol')
		Select nightcontrol
		Use
	Endif
	If Used('nightlog')
		Select nightlog
		Use
	Endif
Endproc

Define Class myrunner As Session OlePublic

	Procedure Init
		Close Tables All
		Close Databases All
		Set Classlib To
		Set Deleted On
		Set Exclusive Off
		Set Safety Off
	Endproc

	Procedure Destroy
		Close Tables All
		Close Databases All
		Set Classlib To
		Set Deleted On
		Set Exclusive Off
		Set Safety Off
	Endproc

	Procedure RunProgram
		Lparameters cProg
		Local cMsg, nLine, nErrnum, cError
		Try
			Do &cProg

		Catch To loException
*			Debug
*			Suspend
			nErrnum = loException.ErrorNo
			cMsg = loException.Message
			nLine = loException.Lineno
			cError = Chr(13)+ ;
			"Error#: " + ;
			Alltrim(Str(nErrnum)) + ;
			"Line #: "+ Alltrim(Str(nLine)) + ;
			": " + Alltrim(cMsg) + ;
			Chr(13)
			This.LogProgress(cError)
		Endtry
	Endproc

	Procedure LogProgress
		Lparameters cStr

		This.OpenLog()
		Select nightlog
		Go Bottom
		Replace Detail With Detail+cStr
	ENDPROC
	
	Function OpenLog()
		Open Database l:\Database\Shared
		If !Used( "nightlog" )
			Use nightlog In 0 Order Id
		Endif
	Endfunc

Enddefine
Jim Newsom
IT Director, ICG Inc.
Next
Reply
Map
View

Click here to load this message in the networking platform