Fossil SCM

Report the time of the last backoffice run in the /stat page for administrators.

drh 2018-08-07 21:21 trunk
Commit ae6e8d97713001c79bec4e362d481e7c810a3b0c885ee31f958fec3f2ab0c348
--- src/backoffice.c
+++ src/backoffice.c
@@ -162,10 +162,21 @@
162162
return z;
163163
}
164164
165165
/*
166166
** Read the "backoffice" property and parse it into a Lease object.
167
+**
168
+** The backoffice property should consist of four integers:
169
+**
170
+** (1) Process ID for the active backoffice process.
171
+** (2) Time (seconds since 1970) for when the active backoffice
172
+** lease expires.
173
+** (3) Process ID for the on-deck backoffice process.
174
+** (4) Time when the on-deck process should expire.
175
+**
176
+** No other process should start active backoffice processing until
177
+** process (1) no longer exists and the current time exceeds (2).
167178
*/
168179
static void backofficeReadLease(Lease *pLease){
169180
Stmt q;
170181
memset(pLease, 0, sizeof(*pLease));
171182
db_prepare(&q, "SELECT value FROM repository.config"
@@ -177,10 +188,30 @@
177188
z = backofficeParseInt(z, &pLease->idNext);
178189
backofficeParseInt(z, &pLease->tmNext);
179190
}
180191
db_finalize(&q);
181192
}
193
+
194
+/*
195
+** Return a string that describes how long it has been since the
196
+** last backoffice run. The string is obtained from fossil_malloc().
197
+*/
198
+char *backoffice_last_run(void){
199
+ Lease x;
200
+ sqlite3_uint64 tmNow;
201
+ double rAge;
202
+ backofficeReadLease(&x);
203
+ tmNow = time(0);
204
+ if( x.tmCurrent==0 ){
205
+ return fossil_strdup("never");
206
+ }
207
+ if( tmNow<=(x.tmCurrent-BKOFCE_LEASE_TIME) ){
208
+ return fossil_strdup("moments ago");
209
+ }
210
+ rAge = (tmNow - (x.tmCurrent-BKOFCE_LEASE_TIME))/86400.0;
211
+ return mprintf("%z ago", human_readable_age(rAge));
212
+}
182213
183214
/*
184215
** Write a lease to the backoffice property
185216
*/
186217
static void backofficeWriteLease(Lease *pLease){
187218
--- src/backoffice.c
+++ src/backoffice.c
@@ -162,10 +162,21 @@
162 return z;
163 }
164
165 /*
166 ** Read the "backoffice" property and parse it into a Lease object.
 
 
 
 
 
 
 
 
 
 
 
167 */
168 static void backofficeReadLease(Lease *pLease){
169 Stmt q;
170 memset(pLease, 0, sizeof(*pLease));
171 db_prepare(&q, "SELECT value FROM repository.config"
@@ -177,10 +188,30 @@
177 z = backofficeParseInt(z, &pLease->idNext);
178 backofficeParseInt(z, &pLease->tmNext);
179 }
180 db_finalize(&q);
181 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
183 /*
184 ** Write a lease to the backoffice property
185 */
186 static void backofficeWriteLease(Lease *pLease){
187
--- src/backoffice.c
+++ src/backoffice.c
@@ -162,10 +162,21 @@
162 return z;
163 }
164
165 /*
166 ** Read the "backoffice" property and parse it into a Lease object.
167 **
168 ** The backoffice property should consist of four integers:
169 **
170 ** (1) Process ID for the active backoffice process.
171 ** (2) Time (seconds since 1970) for when the active backoffice
172 ** lease expires.
173 ** (3) Process ID for the on-deck backoffice process.
174 ** (4) Time when the on-deck process should expire.
175 **
176 ** No other process should start active backoffice processing until
177 ** process (1) no longer exists and the current time exceeds (2).
178 */
179 static void backofficeReadLease(Lease *pLease){
180 Stmt q;
181 memset(pLease, 0, sizeof(*pLease));
182 db_prepare(&q, "SELECT value FROM repository.config"
@@ -177,10 +188,30 @@
188 z = backofficeParseInt(z, &pLease->idNext);
189 backofficeParseInt(z, &pLease->tmNext);
190 }
191 db_finalize(&q);
192 }
193
194 /*
195 ** Return a string that describes how long it has been since the
196 ** last backoffice run. The string is obtained from fossil_malloc().
197 */
198 char *backoffice_last_run(void){
199 Lease x;
200 sqlite3_uint64 tmNow;
201 double rAge;
202 backofficeReadLease(&x);
203 tmNow = time(0);
204 if( x.tmCurrent==0 ){
205 return fossil_strdup("never");
206 }
207 if( tmNow<=(x.tmCurrent-BKOFCE_LEASE_TIME) ){
208 return fossil_strdup("moments ago");
209 }
210 rAge = (tmNow - (x.tmCurrent-BKOFCE_LEASE_TIME))/86400.0;
211 return mprintf("%z ago", human_readable_age(rAge));
212 }
213
214 /*
215 ** Write a lease to the backoffice property
216 */
217 static void backofficeWriteLease(Lease *pLease){
218
+4
--- src/stat.c
+++ src/stat.c
@@ -266,10 +266,14 @@
266266
@ <tr><th>Error Log:</th>
267267
@ <td><a href='%R/errorlog'>%h(g.zErrlog)</a> (%,lld(szFile) bytes)
268268
}
269269
@ </td></tr>
270270
}
271
+ if( g.perm.Admin ){
272
+ @ <tr><th>Backoffice:</th>
273
+ @ <td>Last run: %z(backoffice_last_run())</td></tr>
274
+ }
271275
if( g.perm.Admin && email_enabled() ){
272276
stats_for_email();
273277
}
274278
275279
@ </table>
276280
--- src/stat.c
+++ src/stat.c
@@ -266,10 +266,14 @@
266 @ <tr><th>Error Log:</th>
267 @ <td><a href='%R/errorlog'>%h(g.zErrlog)</a> (%,lld(szFile) bytes)
268 }
269 @ </td></tr>
270 }
 
 
 
 
271 if( g.perm.Admin && email_enabled() ){
272 stats_for_email();
273 }
274
275 @ </table>
276
--- src/stat.c
+++ src/stat.c
@@ -266,10 +266,14 @@
266 @ <tr><th>Error Log:</th>
267 @ <td><a href='%R/errorlog'>%h(g.zErrlog)</a> (%,lld(szFile) bytes)
268 }
269 @ </td></tr>
270 }
271 if( g.perm.Admin ){
272 @ <tr><th>Backoffice:</th>
273 @ <td>Last run: %z(backoffice_last_run())</td></tr>
274 }
275 if( g.perm.Admin && email_enabled() ){
276 stats_for_email();
277 }
278
279 @ </table>
280

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button