1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
3 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure
4 /*--------------------------------------------------------------------------
5 File
: rplctn
/repldump.p
6 Purpose
: Dump un-dumped replication log entries to a replication file
13 ------------------------------------------------------------------------*/
16 {inc
/ofc-set.i
"Replication-MaxLogAge" "c-max-log-age"}
17 {inc
/ofc-set.i
"Replication-MaxFileSize" "c-max-file-size"}
19 DEF VAR max-log-age
AS INT NO-UNDO.
20 DEF VAR max-file-size
AS INT NO-UNDO.
21 ASSIGN max-log-age
= INT(c-max-log-age
) NO-ERROR.
22 ASSIGN max-file-size
= INT(c-max-file-size
) NO-ERROR.
24 IF max-log-age
> -1 THEN .
ELSE max-log-age
= 14.
/* 14 days
*/
25 IF max-file-size
> 16 THEN .
ELSE max-file-size
= 10 * 1024.
/* 10MB
*/
26 max-file-size
= max-file-size
* 1024.
28 /* _UIB-CODE-BLOCK-END
*/
32 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
34 /* ******************** Preprocessor Definitions
******************** */
36 &Scoped-define PROCEDURE-TYPE Procedure
40 /* _UIB-PREPROCESSOR-BLOCK-END
*/
45 /* *********************** Procedure Settings
************************ */
47 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
48 /* Settings for
THIS-PROCEDURE
52 Add Fields to
: Neither
53 Other Settings
: CODE-ONLY
COMPILE
55 &ANALYZE-RESUME _END-PROCEDURE-SETTINGS
57 /* ************************* Create Window
************************** */
59 &ANALYZE-SUSPEND _CREATE-WINDOW
60 /* DESIGN Window definition
(used by the UIB
)
61 CREATE WINDOW Procedure
ASSIGN
64 /* END WINDOW DEFINITION
*/
71 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
74 /* *************************** Main Block
*************************** */
76 DO WHILE CAN-FIND( FIRST ReplLog
WHERE ReplLog.DumpFile
= ""):
80 RUN delete-old-log-entries.
82 /* _UIB-CODE-BLOCK-END
*/
86 /* ********************** Internal Procedures
*********************** */
88 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE delete-old-log-entries Procedure
89 PROCEDURE delete-old-log-entries
:
90 /*------------------------------------------------------------------------------
91 Purpose
: Delete log entries that are more than max-log-age days old.
92 ------------------------------------------------------------------------------*/
93 DEF VAR up-to
AS DATE NO-UNDO.
95 up-to
= TODAY - max-log-age.
97 FOR EACH ReplLog
WHERE ReplLog.ReplDate
< up-to
EXCLUSIVE-LOCK:
103 /* _UIB-CODE-BLOCK-END
*/
107 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE dump-log-entries Procedure
108 PROCEDURE dump-log-entries
:
109 /*------------------------------------------------------------------------------
110 Purpose
: Dump un-dumped log entries
111 ------------------------------------------------------------------------------*/
112 DEF VAR dump-file
AS CHAR NO-UNDO.
113 DEF VAR last-trans
LIKE ReplLog.TransActID
NO-UNDO INITIAL ?.
115 FIND FIRST ReplLog
WHERE ReplLog.DumpFile
= "" NO-LOCK NO-ERROR.
116 IF NOT AVAILABLE ReplLog
THEN RETURN.
118 OS-CREATE-DIR "rplctn/dump".
119 OS-CREATE-DIR "rplctn/dump/tosend".
120 OS-CREATE-DIR "rplctn/dump/toload".
121 OS-CREATE-DIR "rplctn/dump/sent".
122 OS-CREATE-DIR "rplctn/dump/loaded".
124 dump-file
= "rplctn/dump/tosend/" + CAPS( STRING( Office.OfficeCode
, "X(4)" ) ) +
125 STRING( YEAR( TODAY ), "9999" ) +
126 STRING( MONTH( TODAY ), "99" ) +
127 STRING( DAY( TODAY ), "99" ) + REPLACE( STRING( TIME, "HH:MM:SS" ), ":", "" ) +
130 OUTPUT TO VALUE( dump-file
) KEEP-MESSAGES.
131 FIND RP
WHERE RP.UserName
= "Replicate-" + Office.OfficeCode
132 AND RP.ReportID
= "LastFileSent" NO-LOCK NO-ERROR.
133 IF AVAILABLE(RP
) THEN DO:
134 PUT UNFORMATTED ">>>Previous="
135 + SUBSTRING( RP.Char1
, R-INDEX( RP.Char1
, "/") + 1)
140 FOR EACH ReplLog
WHERE ReplLog.DumpFile
= "" EXCLUSIVE-LOCK:
141 IF last-trans
<> ReplLog.TransActID
THEN DO:
142 IF SEEK( OUTPUT ) > max-file-size
THEN LEAVE tp-loop.
143 last-trans
= ReplLog.TransActID.
147 ASSIGN ReplLog.DumpFile
= dump-file.
153 FIND RP
WHERE RP.UserName
= "Replicate-" + Office.OfficeCode
154 AND RP.ReportID
= "LastFileSent" EXCLUSIVE-LOCK NO-ERROR.
155 IF NOT AVAILABLE(RP
) THEN DO:
157 RP.UserName
= "Replicate-" + Office.OfficeCode.
158 RP.ReportID
= "LastFileSent" .
160 RP.Char1
= dump-file.
165 /* _UIB-CODE-BLOCK-END
*/