Unverified Commit 1ae23e77 authored by Nala Ginrut's avatar Nala Ginrut
Browse files

added hook for DB initilization

parent f3731bcf
Pipeline #24398327 failed with stage
in 26 minutes and 43 seconds
......@@ -195,13 +195,17 @@
(define (db-conn-failed-reason conn)
(%db-conn-stat conn cdr))
(define (init-connection-pool)
(display "connection pools are initilizing...")
(let ((poolsize (get-conf '(db poolsize))))
(set! *conn-pool*
(let ((dbconns
(map
(lambda (_) (create-new-DB-conn))
(lambda (_)
(let ((conn (create-new-DB-conn)))
(run-hook *DB-conn-init-hook* conn)
conn))
(iota poolsize))))
(list->queue dbconns)))
(display "DB pool init ok!\n")
......
......@@ -32,6 +32,7 @@
*before-response-hook*
*after-request-hook*
*before-run-hook*
*DB-conn-init-hook*
*sql-mapping-lookup-table*
*artanis-entry*
%current-toplevel
......@@ -81,6 +82,7 @@
(define *before-response-hook* (make-hook 2))
(define *after-request-hook* (make-hook 2))
(define *before-run-hook* (make-hook))
(define *DB-conn-init-hook* (make-hook 1))
;; TODO: I don't have much time for it but it should be RB-Tree in the future
(define *sql-mapping-lookup-table* (make-hash-table))
......
......@@ -70,8 +70,12 @@
(define (init-before-response-hook)
(run-before-response! rc-conn-recycle))
(define (init-startup-hook)
#t)
;; NOTE: If you want to add hook during initialization time, put them here.
(define (init-hook)
(init-startup-hook)
(init-after-request-hook)
(init-before-response-hook))
......
......@@ -72,7 +72,7 @@
keyword->string range oah->handler oah->opts string->keyword
alist->klist alist->kblist is-hash-table-empty?
symbol-downcase symbol-upcase normalize-column run-before-run!
sxml->xml-string run-after-request! run-before-response!
sxml->xml-string run-after-request! run-before-response! run-when-DB-init!
make-pipeline HTML-entities-replace eliminate-evil-HTML-entities
generate-kv-from-post-qstr handle-proper-owner
generate-data-url verify-ENTRY exclude-dbd
......@@ -703,6 +703,9 @@
(define (run-before-run! proc)
(add-hook! *before-run-hook* proc))
(define (run-when-DB-init! proc)
(add-hook! *DB-conn-init-hook* proc))
;; NOTE: For `pipeline' methodology, please read my post:
;; http://nalaginrut.com/archives/2014/04/25/oba-pipeline-style%21
(define (make-pipeline . procs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment