Add %age area column to vacancies section.
[capital-apms-progress.git] / rplctn / repldump.p
blob1beb2180d2222881fe7fa5a6dab54987aba3fa36
1 &ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12
2 &ANALYZE-RESUME
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
8 Description :
10 Author(s) :
11 Created :
12 Notes :
13 ------------------------------------------------------------------------*/
15 {inc/ofc-this.i}
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 */
29 &ANALYZE-RESUME
32 &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK
34 /* ******************** Preprocessor Definitions ******************** */
36 &Scoped-define PROCEDURE-TYPE Procedure
40 /* _UIB-PREPROCESSOR-BLOCK-END */
41 &ANALYZE-RESUME
45 /* *********************** Procedure Settings ************************ */
47 &ANALYZE-SUSPEND _PROCEDURE-SETTINGS
48 /* Settings for THIS-PROCEDURE
49 Type: Procedure
50 Allow:
51 Frames: 0
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
62 HEIGHT = .1
63 WIDTH = 40.
64 /* END WINDOW DEFINITION */
66 &ANALYZE-RESUME
71 &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure
74 /* *************************** Main Block *************************** */
76 DO WHILE CAN-FIND( FIRST ReplLog WHERE ReplLog.DumpFile = ""):
77 RUN dump-log-entries.
78 END.
80 RUN delete-old-log-entries.
82 /* _UIB-CODE-BLOCK-END */
83 &ANALYZE-RESUME
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:
98 DELETE ReplLog.
99 END.
101 END PROCEDURE.
103 /* _UIB-CODE-BLOCK-END */
104 &ANALYZE-RESUME
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" ), ":", "" ) +
128 ".rpl".
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)
136 SKIP.
137 END.
139 tp-loop:
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.
144 END.
146 EXPORT ReplLog.
147 ASSIGN ReplLog.DumpFile = dump-file.
148 END.
150 OUTPUT CLOSE.
152 DO TRANSACTION:
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:
156 CREATE RP.
157 RP.UserName = "Replicate-" + Office.OfficeCode.
158 RP.ReportID = "LastFileSent" .
159 END.
160 RP.Char1 = dump-file.
161 END.
163 END PROCEDURE.
165 /* _UIB-CODE-BLOCK-END */
166 &ANALYZE-RESUME