PDA

View Full Version : Girder Crash During Backup Routine


harleydude
January 22nd, 2007, 09:35 AM
Below is the code for the backup routine I have been working on.
StartJob = function (self, ...)
print ("GirderBackupClass:StartJob() Job Name="..self.Name)
table.print (arg)
local eventstring = arg[1]

if eventstring ~= self.Job.Schedule.EventString then
print("EventString Mismatch, Expecting",self.Job.Schedule.EventString,"Got",eventstring)
return
end

local jobrunning = self.JobThreadID and self.JobThreadID:isthreadrunning ()
if jobrunning or gir.IsLuaExiting () then -- leave if we are already running or lua is shutting down
return
end

self.UpdateThreadID = thread.newthread (self.JobThread,{self})
end,

JobThread = function (self)
print ("GirderBackupClass:JobThread() Job Name="..self.Name)
print ("GirderBackupClass:JobThread() Job Location="..self.BackupDir)

gir.CoInitialize() --initializes the Windows COM system for LuaCom on a secondary thread

local folders = self.Job.Folders
local path = self.Job.Path

--table.print (folders)

local JobRoutine = {

d = date.now(),
MyZip = false,
fs = false,

AddFiles = function (self, id, location)
local loc = self.Path..'\\'..location
local dir = self.fs:GetFolder(loc)
local folders = luacom.GetEnumerator(dir.SubFolders)
local folder = folders:Next()
while folder do
self:AddFiles(id, location..'\\'..folder.Name)
folder = folders:Next()
end
local files = luacom.GetEnumerator(dir.Files)
local file = files:Next()
while file do
--print ('Adding files for location: '..location..'\\'..file.Name)
--print ('location',location)
--print ('file.Name', file.Name)
--print (location, loc)
res, err, msg = self.MyZip:AddFile(location..'\\'..file.Name, loc..'\\'..file.Name)
file = files:Next()
end
end,

BackerUp = function (self, name, output, path, folders)
local OutFile = output..'\\'..name..'_'..self.d.Month..'_'..self.d .Day..'_'..self.d.Year..'.zip'
print ('OutFile', OutFile)
self.Path = path
self.fs = luacom.CreateObject("Scripting.FileSystemObject")
self.MyZip = zip.Open(OutFile, zip.CREATE , zip.FILE)
if self.MyZip then
table.foreach(folders, function (...) return self:AddFiles(unpack(arg)) end)
else
print ('MyZip error')
end
self.MyZip:Close()
self.fs = nil
collectgarbage()
end,
}

JobRoutine:BackerUp (self.Name, self.BackupDir, path, folders)

collectgarbage()
gir.CoUninitialize()
print ("GirderBackupClass:JobThread() Backup Complete")
end,


Last night when the backup routine ran, it crashed Girder. The other day when I was having the AddEvenHandler problem, it was crashing girder. In both instances, if I restarted Grider and ran the backup everything worked. It appears to only crash if Girder has been left alone to run for a period of time before running the routine.

Can you guys see anything wrong with the above code?

Thanks
Rick

Ron
January 22nd, 2007, 09:46 AM
Yeah you are doing COM stuff. Especially from a thread that is asking for trouble. COM will crash Girder if misused.

Promixis
January 22nd, 2007, 10:31 AM
Rick, the file routines in G5 should do everything you need -> or run your code on the main G thread

see

gir.RunCodeOnMainThread (function)

harleydude
January 22nd, 2007, 10:39 AM
Mike,

I will try the File & Directory library routines. I am under the belief that some of the backups could take a bit of time to run. Is it ok/good idea to have them run in a seperate thread?

Rick

Promixis
January 22nd, 2007, 10:46 AM
the lua file routines should be thread safe.

harleydude
January 22nd, 2007, 06:06 PM
Ok, I have converted the script to use the files routines in G, will see what happens tonight. If all goes well in a couple of days I will post it.

Rick