38 lines
1.1 KiB
Racket
38 lines
1.1 KiB
Racket
#lang syndicate/actor
|
|
;; Server Configuration
|
|
|
|
(provide (struct-out config)
|
|
spawn-configuration
|
|
define/query-config
|
|
config-ref)
|
|
|
|
(require racket/file)
|
|
(require/activate syndicate/drivers/filesystem)
|
|
|
|
(struct config (item) #:prefab)
|
|
|
|
(define (spawn-configuration path)
|
|
(actor #:name (list 'configuration-monitor path)
|
|
(during (file-content path file->list $items)
|
|
(cond
|
|
[(not items)
|
|
(log-warning "config ~s is missing" path)]
|
|
[else
|
|
(log-info "loading config ~s" path)
|
|
(for [(item items)]
|
|
(log-info "config ~s: ~s" path item)
|
|
(assert (config item)))]))))
|
|
|
|
(define-syntax define/query-config
|
|
(syntax-rules ()
|
|
[(_ id default)
|
|
(define/query-config id id default)]
|
|
[(_ id key default)
|
|
(define/query-value id default (config (list 'key $val)) val)]))
|
|
|
|
(define (config-ref key default)
|
|
(react/suspend (k)
|
|
(define/query-value actual default (config (list key $val)) val)
|
|
(on-start (flush!)
|
|
(k (actual)))))
|