33 lines
948 B
Racket
33 lines
948 B
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)
|
|
(log-info "config ~s: ~s" path items)
|
|
(for [(item items)]
|
|
(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)))))
|