-
Notifications
You must be signed in to change notification settings - Fork 1
/
pox-notification.scm
36 lines (27 loc) · 1.32 KB
/
pox-notification.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(module pox-notification
(register-notification-handler notification-ref notification-initialize change->notification)
(import chicken scheme)
(use data-structures extras postgresql downtime pox-db pox-db/helpers pox-log)
(define-logger log notification)
(define notification-handlers '())
(define (register-notification-handler name handler)
(set! notification-handlers (alist-update! name handler notification-handlers)))
(define (notification-initialize)
(log (info) "initializing notification handlers")
(with-db-connection
(lambda ()
(for-each (lambda (handler)
(log (debug) "notification handler: ~A" handler)
(condition-case
(unless (db-select-one 'notification_handlers 'name handler 'id)
(query (db-connection) "INSERT INTO notification_handlers (name) VALUES ($1)" handler))
(exn (postgresql) (unless (string=? "23505" (get-condition-property exn 'postgresql 'error-code))
(signal exn)))))
(map (compose symbol->string car) notification-handlers)))))
(define (change->notification user notifyee change)
(sprintf "~A: ~A"
user
(task->item-line (cadr change) notifyee)))
(define (notification-ref name)
(alist-ref name notification-handlers))
)