Event Daemon
Contents
Introduction
The event daemon the part of DrawMGT that runs time-consuming jobs that cannot be completed in the web browser. It runs as a background task and gets its commands (events) from the system database. Users schedule event daemon jobs indirectly via commands such as: transmit submittal, update comment, etc.
The main jobs performed by the event daemon are:
- Submittal and transmittal transmission
- Comment update emails
- Retrieving revision publish files from an FTP site (via the FTP scraper)
- Uploading revision publish files from a local upload directory.
Note: The FTP scraper and upload events have obnly been used on the KEJV project.
Basic Operation of Event Daemom
- The event daemon operates in the background, and is completely separate from the web server.
- The event daemon is activated by a regularly scheduled cron job
The events to be processed are scheduled in the database table Events
The EventDispatcher (in app/events) is the entry point for the event daemon and runs the events.
EventDispatcher calls EventHandlers (in app/events/handlers), based on the eventTypeId that process the actualy events
- The event daemon logs to its own log file, typically in the file var/{site}/{instance}/log/event.log
Many of the event handlers make use of templates defined in the database table Templates.
Implementation
Source Files
Files in app/event/lib
Session.php - A light-weight session that replaces the one in lib/venture/util.
EventCommon.php - A leight-weight version of app/config/Common.php, which includes all needed support files.
EventMap.php - A file which maps eventTypeId to an event handler class name.
EventHandlerBase.php - The base class from which the event handlers are derived.
EventDispatcher.php - The main entry point for the event daemon.
Files in app/event/handlers
CommentUpdateEH.php - Sends comment update emails.
DrawingUploadEH.php - Uploads revision publish files from a local directory.
FtpEH.php - Calls the FTP Scraper program, for uploading files from a remote FTP site.
SubmittalTransmissionEH.php - Sends submittals and transmittals
Event Processing
Comment Update Emails
File: CommentUpdateEH.php
- Has a support function: sendCommentUpdateEmail, for sending emails
Uses templates: CommentUpd-3-0-0-EmailSubject.tpl and CommentUpd-3-0-0-EmailBody.tpl
Drawing Upload
to be completed
FTP Scraper
to be completed
Submittal Transmission
File: SubmittalTransmissionEH.php
- Handles both submittals and transmissions
- Uses tamplates:
- For submittals:
Submit-1-0-0-FormHeader.tpl
Submit-1-0-0-FormBody.tpl
Submit-1-0-0-EmailSubject.tpl
Submit-1-0-0-EmailBody.tpl
- For transmissions:
DocTran-4-0-0-FormHeader.tpl
DocTran-4-0-0-FormBody.tpl
DocTran-4-0-0-EmailSubject.tpl
DocTran-4-0-0-EmailBody.tpl
- For submittals:
Uses external htmldoc to convert the Form templates from HTML into PDF format.
- Sends emails based on user submittal recipient user roles
Uses the zip command to create a ZIP file of all the revision publish files
Event Templates
Many event handlers make use of templates for generating emails, email subject lines, submittal transmission forms, etc.
The templates are defined in the database table Templates
contractId
groupId
submittalTypeId
templateTypeId
code
name
description
filename
0
0
1
1
NULL
1-0-0-FormHeader
Submittal all contract form header
Submit-1-0-0-FormHeader.tpl
0
0
1
2
NULL
1-0-0-FormBody
Submittal all contract form body
Submit-1-0-0-FormBody.tpl
0
0
1
3
NULL
1-0-0-EmailSubject
Submittal all contract email subject
Submit-1-0-0-EmailSubject.tpl
0
0
1
4
NULL
1-0-0-EmailBody
Submittal all contract email body
Submit-1-0-0-EmailBody.tpl
0
0
3
3
NULL
3-0-0-EmailSubject
Comment Update email subject
CommentUpd-3-0-0-EmailSubject.tpl
0
0
3
4
NULL
3-0-0-EmailBody
Comment Update email body
CommentUpd-3-0-0-EmailBody.tpl
0
0
4
1
NULL
4-0-0-FormHeader
DocTran all contract form header
DocTran-4-0-0-FormHeader.tpl
0
0
4
2
NULL
4-0-0-FormBody
DocTran all contract form body
0
0
4
3
NULL
4-0-0-EmailSubject
DocTran all contract subject
DocTran-4-0-0-EmailSubject.tpl
0
0
4
4
NULL
4-0-0-EmailBody
DocTran all contract contract subject
Event Dispatching
Event dispatching is performed by app/event/EventDispatcher.php.
The event dispatcher can be call by cron or from the command line (for testing).
You must be in the DrawMGT root directory (e.g. app/..) in order to run the event daemon.
Events Queued in Database
The event daemon reads queued events from the database table Events.
Field
Type
Descripion
eventId
int
Primary key
eventTypeId
int
References table EventTypeRef
objectId
int
References table ObjectTypeRef
objectTypeId
int
References table ObjectSubTypeRef
stateId
int
References table StateRef
statusId
int
References table StatusRef
priorityId
int
References table PriorityRef
retryCount
int
Number of time event has been processed
attemptNo
int
Attempt number,
runDatetime
datetime
Datetime when event was last processed
plannedDatetime
datetime
Datetime when event should be processed
warningDatetime
datetime
Unimplemented
emergencyDatetime
datetime
Unimplemented
rescheduleOffset
int
Unimplemented
comment
char(128)
Activation by Crontab
- The event daemon is activated automatically by crontab. Here is a typical entry
2-59/3 * * * * cd /home/www/html/dev/linthal113dev ; /usr/local/bin/php -q -C app/event/lib/EventDispatcher.php
Development and Testing Tips
- For testing, the event daemon can be called from the command line:
cd /home/{site}/www/html/prod /usr/local/bin/php -q -C app/event/lib/EventDispatcher.php
- Here is how to reset a previously run event, in order to make it ready to run again:
update Events set runDatetime=null, stateId=3, statusId=null, retryCount=5, attemptNo=0 where eventId = X;