syndicate/drivers/config
This commit is contained in:
parent
97a843ccec
commit
4b99b629df
|
@ -0,0 +1,40 @@
|
||||||
|
#lang syndicate/actor
|
||||||
|
;; Monitor configuration files.
|
||||||
|
|
||||||
|
(provide (struct-out config)
|
||||||
|
spawn-configuration
|
||||||
|
define/query-config
|
||||||
|
config-ref)
|
||||||
|
|
||||||
|
(define-logger syndicate/drivers/config)
|
||||||
|
|
||||||
|
(require racket/file)
|
||||||
|
(require/activate syndicate/drivers/filesystem)
|
||||||
|
|
||||||
|
;; (config Any Any)
|
||||||
|
(struct config (scope item) #:prefab)
|
||||||
|
|
||||||
|
(define (spawn-configuration scope path)
|
||||||
|
(actor #:name (list 'configuration-monitor scope path)
|
||||||
|
(during (file-content path file->list $items)
|
||||||
|
(cond
|
||||||
|
[(not items)
|
||||||
|
(log-syndicate/drivers/config-warning "config ~s is missing" path)]
|
||||||
|
[else
|
||||||
|
(log-syndicate/drivers/config-info "loading config ~s" path)
|
||||||
|
(for [(item items)]
|
||||||
|
(log-syndicate/drivers/config-info "config ~s: ~s" path item)
|
||||||
|
(assert (config scope item)))]))))
|
||||||
|
|
||||||
|
(define-syntax define/query-config
|
||||||
|
(syntax-rules ()
|
||||||
|
[(_ scope id default)
|
||||||
|
(define/query-config id scope id default)]
|
||||||
|
[(_ id scope key default)
|
||||||
|
(define/query-value id default (config scope (list 'key $val)) val)]))
|
||||||
|
|
||||||
|
(define (config-ref #:scope [scope ?] key default)
|
||||||
|
(react/suspend (k)
|
||||||
|
(define/query-value actual default (config scope (list key $val)) val)
|
||||||
|
(on-start (flush!)
|
||||||
|
(k (actual)))))
|
Loading…
Reference in New Issue