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
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