(defmodule lamina_sup
(behaviour supervisor)
(export all))
(defun start_link ()
(supervisor:start_link `#(local lamina_sup) 'lamina_sup '()))
(defun init (_args)
;; 安装前后都拉起仓库进程树:未安装时 start-all 查库失败即可;
;; 否则 Setup 完成后不重启容器,创建仓库会因 repo_mgr 不存在而失败。
(tuple 'ok (tuple #M(strategy one_for_one intensity 5 period 10)
(runtime-child-specs))))
(defun runtime-child-specs ()
(list
(tuple 'lamina_repo_registry
(tuple 'lamina_repo_registry 'start_link '())
'permanent 5000 'worker '())
(tuple 'lamina_repo_mgr
(tuple 'lamina_repo_mgr 'start_link '())
'permanent 5000 'worker '())
(tuple 'lamina_sync_sched
(tuple 'lamina_sync_sched 'start_link '())
'permanent 5000 'worker '())))
(defun ensure-runtime ()
(lists:foreach #'ensure-child/1 (runtime-child-specs)))
(defun ensure-child (spec)
(let ((id (element 1 spec)))
(case (catch (supervisor:start_child 'lamina_sup spec))
(`#(ok ,_) 'ok)
(`#(error #(already_started ,_)) 'ok)
(`#(error #(already_present ,_))
(catch (supervisor:restart_child 'lamina_sup id))
'ok)
(_ 'ok))))