Actually close database connections
Previously, the connections were not closed, so eventually PostgreSQL would run out. Using a pool of connections would be better, but as a short term solution, just close the connection after each request.
This commit is contained in:
parent
5a9262b38d
commit
0a49c0a84a
|
@ -50,9 +50,7 @@
|
|||
;; (render-html (error-page message))))
|
||||
)
|
||||
|
||||
(define (controller request body)
|
||||
(define conn (connect-to-postgres-paramstring "dbname=guix_data_service"))
|
||||
|
||||
(define (controller request body conn)
|
||||
(match-lambda
|
||||
((GET)
|
||||
(apply render-html (index (most-recent-n-guix-revisions conn 10))))
|
||||
|
|
|
@ -21,15 +21,32 @@
|
|||
#:use-module (web http)
|
||||
#:use-module (web request)
|
||||
#:use-module (web uri)
|
||||
#:use-module (squee)
|
||||
#:use-module (fibers web server)
|
||||
#:use-module (guix-data-service web controller)
|
||||
#:use-module (guix-data-service web util)
|
||||
#:export (start-guix-data-service-web-server))
|
||||
|
||||
;; TODO This isn't exported for some reason
|
||||
(define pg-conn-finish
|
||||
(@@ (squee) pg-conn-finish))
|
||||
|
||||
(define (with-postgresql-connection paramstring f)
|
||||
(let* ((conn (connect-to-postgres-paramstring paramstring)))
|
||||
(dynamic-wind
|
||||
(const #t)
|
||||
(lambda ()
|
||||
(f conn))
|
||||
(lambda ()
|
||||
(pg-conn-finish conn)))))
|
||||
|
||||
(define (run-controller controller request body)
|
||||
((controller request body)
|
||||
(cons (request-method request)
|
||||
(request-path-components request))))
|
||||
(with-postgresql-connection
|
||||
"dbname=guix_data_service"
|
||||
(lambda (conn)
|
||||
((controller request body conn)
|
||||
(cons (request-method request)
|
||||
(request-path-components request))))))
|
||||
|
||||
(define (handler request body controller)
|
||||
(format #t "~a ~a\n"
|
||||
|
|
Loading…
Reference in New Issue