︙ | | |
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
+
+
+
|
;;======================================================================
;;======================================================================
;; C L I E N T S
;;======================================================================
(define *http-mutex* (make-mutex))
;; NOTE: Large block of code from 32436b426188080f72fceb6894af541fbad9921e removed here
;; I'm pretty sure it is defunct.
;; This next block all imported en-mass from the api branch
(define *http-requests-in-progress* 0)
(define *http-connections-next-cleanup* (current-seconds))
(define (http-transport:get-time-to-cleanup)
(let ((res #f))
|
︙ | | |
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
-
+
|
(* 3 24 60 60)))))
(debug:print-info 2 "server-timeout: " server-timeout ", server pid: " spid " on " iface ":" port)
(let loop ((count 0))
;; Use this opportunity to sync the inmemdb to db
(let ((start-time (current-milliseconds))
(sync-time #f)
(rem-time #f))
(if *inmemdb* (db:sync-tables (db:tbls *inmemdb*) *inmemdb* *db*)) ;; (db:sync-to *inmemdb* *db*))
(if *inmemdb* (db:sync-touched *inmemdb*))
(set! sync-time (- (current-milliseconds) start-time))
(debug:print 0 "SYNC: time= " sync-time)
(set! rem-time (quotient (- 4000 sync-time) 1000))
(if (and (< rem-time 4)
(> rem-time 0))
(thread-sleep! rem-time)))
|
︙ | | |
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
-
+
|
(begin
(debug:print-info 0 "Server continuing, seconds since last db access: " (- (current-seconds) last-access))
(loop 0))
(begin
(debug:print-info 0 "Starting to shutdown the server.")
;; need to delete only *my* server entry (future use)
(set! *time-to-exit* #t)
(if *inmemdb* (db:sync-tables (db:tbls *inmemdb*) *inmemdb* *db*)) ;; (db:sync-to *inmemdb* *db*))
(if *inmemdb* (db:sync-touched *inmemdb*))
(open-run-close tasks:server-deregister-self tasks:open-db (get-host-name))
(thread-sleep! 1)
(debug:print-info 0 "Max cached queries was " *max-cache-size*)
(debug:print-info 0 "Number of cached writes " *number-of-writes*)
(debug:print-info 0 "Average cached write time "
(if (eq? *number-of-writes* 0)
"n/a (no writes)"
|
︙ | | |
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
|
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
(if *toppath*
(let* ((th2 (make-thread (lambda ()
(http-transport:run
(if (args:get-arg "-server")
(args:get-arg "-server")
"-"))) "Server run"))
(th3 (make-thread http-transport:keep-running "Keep running")))
;; (th1 (make-thread server:write-queue-handler "write queue")))
(set! *cache-on* #t)
;; Database connection
(set! *db* (open-db))
(set! *inmemdb* (open-in-mem-db))
(set! *inmemdb* (make-dbr:dbstruct path: *toppath*))
(db:sync-tables (db:tbls *db*) *db* *inmemdb*) ;; (db:sync-to *db* *inmemdb*)
(thread-start! th2)
(thread-start! th3)
;; (thread-start! th1)
(set! *didsomething* #t)
(thread-join! th2))
(debug:print 0 "ERROR: Failed to setup for megatest")))
(exit)))
;; (use trace)
;; (trace http-transport:keep-running
;; tasks:server-update-heartbeat
;; tasks:server-get-server-id)
;; tasks:get-best-server
;; http-transport:run
;; http-transport:launch
;; http-transport:try-start-server
;; http-transport:client-send-receive
;; http-transport:make-server-url
;; tasks:server-register
;; tasks:server-delete
;; start-server
;; hostname->ip
;; with-input-from-request
;; tasks:server-deregister-self)
(define (http-transport:server-signal-handler signum)
(handle-exceptions
exn
(debug:print " ... exiting ...")
(let ((th1 (make-thread (lambda ()
(thread-sleep! 1))
;; (if (not *received-response*)
;; (receive-message* *runremote*))) ;; flush out last call if applicable
"eat response"))
(th2 (make-thread (lambda ()
(debug:print 0 "ERROR: Received ^C, attempting clean exit. Please be patient and wait a few seconds before hitting ^C again.")
(thread-sleep! 3) ;; give the flush three seconds to do it's stuff
(debug:print 0 " Done.")
(exit 4))
"exit on ^C timer")))
|
︙ | | |