 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
mlr0911
Joined: 13 Jul 2007 Posts: 35 Country: United States |
|
File Watch |
|
I have a file watch in place (thanks to your help), however, when the file isn't found it loops until it is found. WHen it is found, I have the code going to a "Check_File" call, but it is saying that the file can't be found. Do you know why this is? When I stop testing and restart the job, it finds the file and moves it.
Example:
Code searches for Fileexists( "x:\\ckl1_*.txt", found) and if isn't found it loops. When it is found, I try to access the file by
FileOpen ( BT200,"StreamMode","Read","",File_handle1) , but it states it isn't found, but the Fileexists( "x:\\ckl1_*.txt", found) already found the file.
Any thoughts on what I can do?
 |
 |
//Check to see if a file exsists, if so, wait to execute FTP Process.
//If not, wait until we find it.
ONERRORGOTO LETS_WAIT
Dim found, boolean
Dim not_found, boolean
Dim wait_time, number
Dim File_Handle1, number
dim file_handle2, number
dim file_handle3, number
Dim timeout, boolean
Dim (BT200, string)
Dim (BT201, string)
Dim (BT202, string)
Dim path, string
Dim file_name, string
Dim (process_id, number)
Dim count, number
//Statement Location
DirEx ("x:\\ckl1_*.txt",BT200)
DirEx ("x:\\ckl2_*.txt",BT201)
DirEx ("x:\\ckl3_*.txt",BT202)
//Check to see if file exsists
Lets_Check_File:
Fileexists( "x:\\ckl1_*.txt", found)
Fileexists( "x:\\ckl2_*.txt",found)
FileExists( "x:\\ckl3_*.txt",found)
ifthen (found, CHECK_FILE )
goto lets_wait
//If found try to open the document, if can't, goto Lets_Wait
Check_file:
Messagebox "Found"
FileOpen ( BT200,"StreamMode","Read","",File_handle1)
Fileopen ( BT201, "streammode","Read","",File_Handle2)
FileOpen ( BT202, "StreamMode","Read","",File_Handle3)
LoopUntil FILE_HANDLE3, End_Loop
exit
Lets_Wait:
wait, 1
messagebox "I'm waiting"
goto Lets_Check_File
//Ready to MOVE
End_Loop:
Messagebox "Loop Finished, ready to move"
fileclose (file_handle1)
fileclose (file_Handle2)
Fileclose (file_handle3)
goto MOVE
onErrorStop
MOVE:
messagebox "Move Time"
//Need a file move here so that once they are moved, backups will be able to start
//Find out where we want to move these (TEMP)
FileMoveEx( "x:\\ckl1_*.txt", "h:\\24x7", count )
FileMoveEx( "x:\\ckl2_*.txt", "h:\\24x7", count )
FileMoveEx( "x:\\ckl3_*.txt", "h:\\24x7", count )
MailSend "abcd@chester.com", &
"", &
"mriggs@chester.com", &
"Execute Att1 & Att2 Backups ", &
"Please release backup jobs Att1 and Att2 on the Trust server."
|
Thanks for your help.
Last edited by mlr0911 on Thu Nov 01, 2007 10:22 am; edited 1 time in total |
|
Wed Oct 31, 2007 4:42 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
|
|
I see a number of problems with this script, among them are the following.
Problem # 1
 |
 |
Fileexists( "x:\\ckl1_*.txt", found)
Fileexists( "x:\\ckl2_*.txt",found)
FileExists( "x:\\ckl3_*.txt",found) |
Results of the first fileexists are ignored because the second fileexists overwrites the value returned by the first one. The results of the second file exists are also ignored because its results overwritten by the third file exists. So effectively you only have the last FileExists functioning, first 2 are smply ignored.
Of course when you try to do FileOpen ( BT200,"StreamMode","Read","",File_handle1) you get an error if there are no such files. Based on your script, I will try to help you with the logic.
Problem 2
OnError... statement is misused. It causes dead loop in case of any errors.
Problem 3.
What if you have multiple files that match the mask? How are you going to open them? FileOpen can only open 1 file at a time.
 |
 |
Dim found1, boolean
Dim found2, boolean
Dim found3, boolean
Dim multiple_files, number
Dim all_found, boolean
Dim wait_time, number, 60
Dim total_wait_time, number
Dim max_wait_time, number, 3600
Dim File_Handle, number
Dim timeout, boolean
Dim BT200, string
Dim BT201, string
Dim BT202, string
Dim count, number
START_OVER:
//Statement Location
DirEx ("x:\\ckl1_*.txt",BT200)
DirEx ("x:\\ckl2_*.txt",BT201)
DirEx ("x:\\ckl3_*.txt",BT202)
//Check to see if file exsists
Lets_Check_File:
NotEqual( BT200, "", found1)
NotEqual( BT201, "", found2)
NotEqual( BT202, "", found3)
InStr( BT200, ",", 0, multiple_files)
IfThen( multiple_files, REPORT_MULTIFILE_ERROR )
InStr( BT201, ",", 0, multiple_files)
IfThen( multiple_files, REPORT_MULTIFILE_ERROR )
InStr( BT202, ",", 0, multiple_files)
IfThen( multiple_files, REPORT_MULTIFILE_ERROR )
And ( found1, found2, all_found )
And( all_found, found3, all_found )
IfThen( all_found, CHECK_FILE_LOCKING )
// if we are here, we didn't find the required 3 files
// Wait and try again
Wait wait_time
Add total_wait_time, wait_time, total_wait_time
// you can add here check for timeouts here, need to calculate total wait time
IsGreater total_wait_time, max_wait_time, timeout
IfThen( timeout, REPORT_TIMEOUT_ERROR )
GoTo START_OVER
//If found try to open the document, if can't, wait a little bit and try again
CHECK_FILE_LOCKING:
ONERRORGOTO FILE_LOCKED
FileOpen ( BT200, "StreamMode","Read","", File_handle)
FileClose( file_handle)
FileOpen ( BT201, "StreamMode","Read","", File_handle)
FileClose( file_handle)
FileOpen ( BT202, "StreamMode","Read","", File_handle)
FileClose( file_handle)
// if we are here, we were able to open/close all 3 files
OnErrorStop
Messagebox "Loop Finished, ready to move"
FileMoveEx( "x:\\ckl1_*.txt", "h:\\24x7", count )
FileMoveEx( "x:\\ckl2_*.txt", "h:\\24x7", count )
FileMoveEx( "x:\\ckl3_*.txt", "h:\\24x7", count )
//Need a file move here so that once they are moved, backups will be able to start
//Find out where we want to move these (TEMP)
MailSend ("abcd@chester.com", "", "mriggs@chester.com", "Execute Att1 & Att2 Backups", &
"Please release backup jobs Att1 and Att2 on the Trust wil-truadv01 server." )
Exit
FILE_LOCKED:
// if we are here, this is because we couldn't open all 3 files and they are still locked
OnErrorStop
// wait and try again
Wait(wait_time)
GoTo CHECK_FILE_LOCKING
REPORT_TIMEOUT_ERROR:
MailSend( "abcd@chester.com", "", "mriggs@chester.com", "Execute Att1 & Att2 Backups - job error", &
"Timeout occurred while waiting for files." )
Exit
REPORT_MULTIFILE_ERROR:
MailSend( "abcd@chester.com", "", "mriggs@chester.com", "Execute Att1 & Att2 Backups - job error", &
"Multiple files found. Unable to check their lock state." )
Exit
|
|
|
Wed Oct 31, 2007 7:09 pm |
|
 |
mlr0911
Joined: 13 Jul 2007 Posts: 35 Country: United States |
|
|
|
Wow, thanks for your help with this.
|
|
Thu Nov 01, 2007 10:26 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
|
|
You are welcome.
To make it even better I suggest adding LogAddMessageEx calls next to each MailSend so you can get a copy of the error or status message in the job log and also insert LogAddMessageEx before "GoTo CHECK_FILE_LOCKING" just to have a record in the log that the job has found all required files, but still waiting because some of these files are being locked. This might help you to troubleshoot things in case if files are locked and never released.
Example:
 |
 |
LogAddMessageEx("WARNING", @V"job_id", "@V"job_name"", "Found all 3 files, but still waiting because some files are still being processed" ) |
|
|
Thu Nov 01, 2007 10:48 am |
|
 |
mlr0911
Joined: 13 Jul 2007 Posts: 35 Country: United States |
|
|
|
Great idea....
Is there also a way to make the mail message do a line return like VB chr(13)?
Example:
Jobs have been released.
Thank You,
|
|
Thu Nov 01, 2007 10:56 am |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7955
|
|
|
|
Line1\r\nLine2
\r - is for carriage return symbol ASCII code 13 , \n is for line feed (new line) ASCII code 10
|
|
Thu Nov 01, 2007 11:10 am |
|
 |
|
|
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
|
|
|