Fossil SCM
Report the time of the last backoffice run in the /stat page for administrators.
Commit
ae6e8d97713001c79bec4e362d481e7c810a3b0c885ee31f958fec3f2ab0c348
Parent
43c29877be3939b…
2 files changed
+31
+4
+31
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -162,10 +162,21 @@ | ||
| 162 | 162 | return z; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /* |
| 166 | 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). | |
| 167 | 178 | */ |
| 168 | 179 | static void backofficeReadLease(Lease *pLease){ |
| 169 | 180 | Stmt q; |
| 170 | 181 | memset(pLease, 0, sizeof(*pLease)); |
| 171 | 182 | db_prepare(&q, "SELECT value FROM repository.config" |
| @@ -177,10 +188,30 @@ | ||
| 177 | 188 | z = backofficeParseInt(z, &pLease->idNext); |
| 178 | 189 | backofficeParseInt(z, &pLease->tmNext); |
| 179 | 190 | } |
| 180 | 191 | db_finalize(&q); |
| 181 | 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 | +} | |
| 182 | 213 | |
| 183 | 214 | /* |
| 184 | 215 | ** Write a lease to the backoffice property |
| 185 | 216 | */ |
| 186 | 217 | static void backofficeWriteLease(Lease *pLease){ |
| 187 | 218 |
| --- 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 @@ | ||
| 266 | 266 | @ <tr><th>Error Log:</th> |
| 267 | 267 | @ <td><a href='%R/errorlog'>%h(g.zErrlog)</a> (%,lld(szFile) bytes) |
| 268 | 268 | } |
| 269 | 269 | @ </td></tr> |
| 270 | 270 | } |
| 271 | + if( g.perm.Admin ){ | |
| 272 | + @ <tr><th>Backoffice:</th> | |
| 273 | + @ <td>Last run: %z(backoffice_last_run())</td></tr> | |
| 274 | + } | |
| 271 | 275 | if( g.perm.Admin && email_enabled() ){ |
| 272 | 276 | stats_for_email(); |
| 273 | 277 | } |
| 274 | 278 | |
| 275 | 279 | @ </table> |
| 276 | 280 |
| --- 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 |