Megatest

Diff
Login

Differences From Artifact [c88d2a22c9]:

To Artifact [351c29f44d]:


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33






34
35
36
37
38
39
40
;;     GNU General Public License for more details.
;; 
;;     You should have received a copy of the GNU General Public License
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.
;;
;;======================================================================

(use srfi-69 posix)

(declare (unit api))
(declare (uses rmt))
(declare (uses db))
(declare (uses dbmod))
(declare (uses dbfile))
(declare (uses tasks))


(import dbmod)
(import dbfile)







;; allow these queries through without starting a server
;;
(define api:read-only-queries
  '(get-key-val-pairs
    get-var
    get-keys







<
<






>



>
>
>
>
>
>







16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;     GNU General Public License for more details.
;; 
;;     You should have received a copy of the GNU General Public License
;;     along with Megatest.  If not, see <http://www.gnu.org/licenses/>.
;;
;;======================================================================



(declare (unit api))
(declare (uses rmt))
(declare (uses db))
(declare (uses dbmod))
(declare (uses dbfile))
(declare (uses tasks))
(declare (uses tcp-transportmod))

(import dbmod)
(import dbfile)
(import tcp-transportmod)

(use srfi-69
     posix
     matchable
     s11n)

;; allow these queries through without starting a server
;;
(define api:read-only-queries
  '(get-key-val-pairs
    get-var
    get-keys
223
224
225
226
227
228
229
230


231
232
233
234
235
236
237
238
239
240
241
242
243




244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
             (begin
               #;(common:telemetry-log (conc "api-out:"(->string cmd))
               payload: `((params . ,params)
               (ok-res . #f)))
               (vector #t res))))))))

;; indat is (cmd run-id params meta)
(define (api:tcp-dispatch-request dbstruct indat) ;; cmd run-id params)


  (set! *api-process-request-count* (+ *api-process-request-count* 1))
  (match (deserialize indat)
    ((cmd run-id params meta)
     (let* ((status  (cond
		      ((> *api-process-request-count* 50) 'busy)
		      ((> *api-process-request-count* 25) 'loaded)
		      (else 'ok)))
	    (errmsg  (case status
		       ((busy)   (conc "Server overloaded, "*api-process-request-count*" threads in flight"))
		       ((loaded) (conc "Server loaded, "*api-process-request-count*" threads in flight"))
		       (else     #f)))
	    (result  (case status
		       ((busy) #f)




		       (else (api:dispatch-request dbstruct cmd run-id params))))
	    (payload (list status errmsg result '()))
	    (pdat    (serialize payload)))
       (set! *api-process-request-count* (- *api-process-request-count* 1))
       pdat))
    (else
     (let* ((msg (conc "(deserialize indat)="(deserialize indat)", indat="indat)))
       (assert #f "FATAL: failed to deserialize indat "msg)))))
       

(define (api:dispatch-request dbstruct cmd run-id params)
  (case cmd
    ;;===============================================
    ;; READ/WRITE QUERIES
    ;;===============================================







|
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
|
|
<
|
|
|
<
|







228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

257
258
259

260
261
262
263
264
265
266
267
             (begin
               #;(common:telemetry-log (conc "api-out:"(->string cmd))
               payload: `((params . ,params)
               (ok-res . #f)))
               (vector #t res))))))))

;; indat is (cmd run-id params meta)
(define (api:tcp-dispatch-request-make-handler dbstruct) ;; cmd run-id params)
  (lambda ()
    (let* ((indat (deserialize)))
      (set! *api-process-request-count* (+ *api-process-request-count* 1))
      (match indat
	((cmd run-id params meta)
	 (let* ((status  (cond
			  ((> *api-process-request-count* 50) 'busy)
			  ((> *api-process-request-count* 25) 'loaded)
			  (else 'ok)))
		(errmsg  (case status
			   ((busy)   (conc "Server overloaded, "*api-process-request-count*" threads in flight"))
			   ((loaded) (conc "Server loaded, "*api-process-request-count*" threads in flight"))
			   (else     #f)))
		(result  (case status
			   ((busy) #f)
			   (else
			    (case cmd
			      ((ping) (tt:mk-signature *toppath*))
			      (else
			       (api:dispatch-request dbstruct cmd run-id params))))))
		(payload (list status errmsg result '())))

	   (set! *api-process-request-count* (- *api-process-request-count* 1))
	   (serialize payload)))
	(else

	 (assert #f "FATAL: failed to deserialize indat "indat))))))
       

(define (api:dispatch-request dbstruct cmd run-id params)
  (case cmd
    ;;===============================================
    ;; READ/WRITE QUERIES
    ;;===============================================