Recording start and finish times for a function
Jan 21 2010
The previous post showed how to get the name of the called function in a component. This post will show how this is used. Each function has the following three lines.
2<cfset var myResult = application.reportEODCollectData.start( arguments.endDate, "#myName#" ) />
3<cfif myResult EQ "Start">
The first line gets the name of the function. The second line calls the start function which will check if the function has been previously called today. If it has not, it will add the name and time. As you can see, some other checking is done to alert of any problems. The third line determines if the rest of the function runs.
At the end of each function, the following code is added.
2 <cfset myReturn = "Complete" />
3 <cfelse>
4 <cfset myReturn = "ErrorEnd" />
5 </cfif>
6<cfelse>
7 <cfset myReturn = "#myResult#" />
8</cfif>
If the function code runs, the end time is recorded and all ends well. If it did not end well, it will rteturn an error and that is handled elsewhere.
This may seem a little over the top, but the timing of the dataset collection and knowing how log it took to collect each dataset is critical.
This is the start and end functions.
2 <cfargument name="theDate" type="date" required="true">
3 <cfargument name="report" type="string" required="true">
4
5 <cfset var g = "" />
6 <cfset var i = "" />
7 <cfset var myReturn = "" />
8
9 <cfquery name="g" dataSource="#variables.dsn#">
10 SELECT
11 *
12 FROM
13 a_report
14 WHERE
15 statDate = #arguments.theDate#
16 AND report = '#arguments.report#'
17 </cfquery>
18 <cfif g.recordCount EQ 0>
19 <cfquery name="i" dataSource="#variables.dsn#">
20 INSERT INTO
21 a_report
22 (statDate,
23 report,
24 dateTimeStart)
25 VALUES
26 (#arguments.theDate#,
27 '#arguments.report#',
28 #now()#)
29 </cfquery>
30 <cfset myReturn = "Start" />
31 <cfelseif g.recordCount EQ 1 AND g.dateTimeEnd GT 0>
32 <cfset myReturn = "AlreadyComplete" />
33 <cfelseif g.recordCount EQ 1 AND g.dateTimeEnd EQ ''>
34 <cfset myReturn = "FinishFailed" />
35 <cfelse>
36 <cfset myReturn = "Error" />
37 </cfif>
38 <cfreturn myReturn>
39</cffunction>
40
41<cffunction name="end" returnType="string" output="false">
42 <cfargument name="theDate" type="date" required="true">
43 <cfargument name="report" type="string" required="true">
44
45 <cfset var g = "" />
46 <cfset var u = "" />
47 <cfset var myReturn = "" />
48
49 <cfquery name="g" dataSource="#variables.dsn#">
50 SELECT
51 id
52 FROM
53 a_report
54 WHERE
55 statDate = #arguments.theDate#
56 AND report = '#arguments.report#'
57 </cfquery>
58 <cfif g.recordCount EQ 1>
59 <cfquery name="u" dataSource="#variables.dsn#">
60 UPDATE
61 a_report
62 SET
63 dateTimeEnd = #now()#
64 WHERE
65 id = #g.id#
66 </cfquery>
67 <cfset myReturn = "Finish" />
68 <cfelse>
69 <cfset myReturn = "FinishError" />
70 </cfif>
71 <cfreturn myReturn>
72</cffunction>









