PDA

View Full Version : AddEventHandler Confusion


harleydude
January 20th, 2007, 04:00 PM
In my GirderBackup plugin I am using gir.AddEventHandler to trigger the backup scripts. I have 2 backup scripts loaded and waiting to be triggered. I am using the Scheduler plugin to provide the triggers.

Scheduler Eventstring 1 = Backup
Scheduler Eventstring 2 = Backup2

If I trigger Backup then the script waiting for that eventstring is ran, if I trigger Backup2 then both scripts are ran.

Ouput when Backup is triggered.
GirderBackupClass:StartJob() Job Name=Girder
{
[1] = "Backup",
[2] = 10031,
[3] = 0,
[4] = {
},
[5] = 1203,
["n"] = 5,
}
GirderBackupClass:JobThread() Job Name=Girder
GirderBackupClass:JobThread() Job Location=D:\Program Files\Promixis\Girder5\Backups
GirderBackupClass:JobThread() Backup Complete


Ouput when Backup2 is triggered.
GirderBackupClass:StartJob() Job Name=Girder
{
[1] = "Backup2",
[2] = 10031,
[3] = 0,
[4] = {
},
[5] = 1203,
["n"] = 5,
}
EventString Mismatch, Expecting Backup Got Backup2
GirderBackupClass:StartJob() Job Name=Backup 2
{
[1] = "Backup2",
[2] = 10031,
[3] = 0,
[4] = {
},
[5] = 1204,
["n"] = 5,
}
GirderBackupClass:JobThread() Job Name=Backup 2
GirderBackupClass:JobThread() Job Location=D:\Program Files\Promixis\Girder5\Backups
GirderBackupClass:JobThread() Backup Complete


Here is how I am setting up the eventhandler
local eventstring = self.Job.Schedule.EventString
local device = self.Job.Schedule.PluginID
self.EventHandler = gir.AddEventHandler(eventstring,device,device, function (...) return self:StartJob(unpack(arg)) end)


Any ideas?

Rick

Rob H
January 20th, 2007, 04:11 PM
I think you need to modify your event strings slightly. Unfortunately the regular expressions used by the event handling code aren't Lua style regexps and I can't remember what format they actually use - might be PCRE.

The simplest solution would be to rename the first event string Backup1 - better would be to change your call to AddEventHandler to be

self.EventHandler = gir.AddEventHandler('^'..eventstring..'$',device,d evice, function (...) return self:StartJob(unpack(arg)) end)

Which will force it to match the whole string only.

harleydude
January 20th, 2007, 04:36 PM
I changed the AddEventHandler per your suggestion and things work as expected now.

Thanks
Rick

Rob H
January 20th, 2007, 06:23 PM
Glad to hear it :)

danward79
January 21st, 2007, 04:44 AM
Sounds like an interesting plugin. I look forward to trying it.