Explorar o código

Merge pull request #6962 from overleaf/jpa-clsi-tweak-health-check

[clsi] tweak health check

GitOrigin-RevId: 2caad90d55bb441c7008e3084b34d683b072dfbd
Jakob Ackermann %!s(int64=4) %!d(string=hai) anos
pai
achega
b25ff076b8

+ 9 - 1
services/clsi/app.js

@@ -271,10 +271,18 @@ if (Settings.processLifespanLimitMs) {
 
 function runSmokeTest() {
   if (Settings.processTooOld) return
+  const INTERVAL = 30 * 1000
+  if (
+    smokeTest.lastRunSuccessful() &&
+    Date.now() - CompileController.lastSuccessfulCompile < INTERVAL / 2
+  ) {
+    logger.log('skipping smoke tests, got recent successful user compile')
+    return setTimeout(runSmokeTest, INTERVAL / 2)
+  }
   logger.log('running smoke tests')
   smokeTest.triggerRun(err => {
     if (err) logger.error({ err }, 'smoke tests failed')
-    setTimeout(runSmokeTest, 30 * 1000)
+    setTimeout(runSmokeTest, INTERVAL)
   })
 }
 if (Settings.smokeTest) {

+ 3 - 0
services/clsi/app/js/CompileController.js

@@ -27,6 +27,8 @@ function isImageNameAllowed(imageName) {
 }
 
 module.exports = CompileController = {
+  lastSuccessfulCompile: 0,
+
   compile(req, res, next) {
     if (next == null) {
       next = function () {}
@@ -87,6 +89,7 @@ module.exports = CompileController = {
                 for (file of Array.from(outputFiles)) {
                   if (file.path === 'output.pdf' && file.size > 0) {
                     status = 'success'
+                    CompileController.lastSuccessfulCompile = Date.now()
                   }
                 }
 

+ 6 - 0
services/clsi/test/smoke/js/SmokeTests.js

@@ -19,6 +19,9 @@ module.exports = {
       cb(error)
     })
   },
+  lastRunSuccessful() {
+    return this._lastError == null
+  },
 
   _lastError: new Error('SmokeTestsPending'),
   _sendResponse(res, error) {
@@ -39,6 +42,9 @@ module.exports = {
         url,
         json: {
           compile: {
+            options: {
+              metricsPath: 'health-check',
+            },
             resources: [
               {
                 path: 'main.tex',