Announcement

Collapse
No announcement yet.

Events dropping file writes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Events dropping file writes

    Hi,

    I have two events that each run a script which in turns appends to the same file. Frequently the write is not happening. Apparently the events are executing faster than it can append to a file.

    So that makes me what to ask what the two script options are:
    * "Wait for script before continuing". Does this "block" on on this event until completion (like before it executes other Then statements) or are all events held up?
    * "Allow only one instance to run at a time". Does this mean another instance will wait? Or?

    Thanks for any insight on these two questions. Plus any strategies for two events writing to the same file.

    Tahl

    #2
    Unless you were running the events extremely quickly at precisely the same time then I would still expect it to be able to write to a file, however what sort of function are you using, are you closing the file after the write or leaving it open?

    The event script options to wait before continuing I have tested and they do block, the one instance I think may have had some issues in the past but may be working now. I believe that it should just allow one script to run at the time so if you have two events calling it and it is still open in the first then it wouldn't run the second.

    Comment


      #3
      Originally posted by tahl View Post
      I have two events that each run a script which in turns appends to the same file. Frequently the write is not happening. Apparently the events are executing faster than it can append to a file.
      Are the events asynchronous? If not, can you combine them?

      If they are, you might try adding a test to your scripts (hs.IsScriptRunning) to test if the other script that writes to the file is running and if so to wait a few msec and try again. Alternatively, you could use Try/Catch to detect file write errors and repeat the write action if it is unsuccessful.
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

      Comment


        #4
        Originally posted by mrhappy View Post
        Unless you were running the events extremely quickly at precisely the same time then I would still expect it to be able to write to a file, however what sort of function are you using, are you closing the file after the write or leaving it open?

        The event script options to wait before continuing I have tested and they do block, the one instance I think may have had some issues in the past but may be working now. I believe that it should just allow one script to run at the time so if you have two events calling it and it is still open in the first then it wouldn't run the second.
        @mrhappy, here's my script:

        Code:
        Sub Main(Parm)
            Const ForAppending = 8
            Dim fso, fFile, Filename, LogEntry
        
            parms = Split(Parm,"|")
            hs.WriteLog "DEBUG","Parms " & parms(0) & "," & parms(1)
        
            Filename = "c:\Logging\Level1\zzliam1-" & parms(0) + ".log"
            LogEntry = FormatDateTime(Now,vbShortDate) & " " & Time & "  " & parms(1) 
        
            Set fso = CreateObject("Scripting.FileSystemObject")
            Set fFile = fso.OpenTextFile(Filename,ForAppending,True)
            fFile.WriteLine(LogEntry)
            fFile.Close : Set fFile = Nothing    
        
        End Sub
        ...so yes I am closing the file. If two events respond to the same trigger and so execute sequentially, and both execute this script, one of them will _not_ write the file. There's no error in the log. It's 100% reproducible.

        Note I _don't_ check the box for "wait" nor do I check the box for allowing only "one instance" to run. Should I check them? Other ideas?

        Thanks,
        Tahl

        Comment


          #5
          Originally posted by Uncle Michael View Post
          Are the events asynchronous? If not, can you combine them?

          If they are, you might try adding a test to your scripts (hs.IsScriptRunning) to test if the other script that writes to the file is running and if so to wait a few msec and try again. Alternatively, you could use Try/Catch to detect file write errors and repeat the write action if it is unsuccessful.
          @UncleMichael, both good ideas. I'll try the former first. I'm currently using VBScript so can't do the latter unless I convert to VB, which I don't know but can probably figure out....

          Tahl

          Comment

          Working...
          X