-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.lisp
31 lines (26 loc) · 802 Bytes
/
task.lisp
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
(in-package #:guarded-commands)
(defvar *task-rollback* nil "The list of rollback functions to be called in the event a step fails.")
;; FIXME: make docstrings and declare forms work
(defmacro define-task (name args &body body)
"Defines a task, within which steps and rollbacks can be used."
(multiple-value-bind (body decl doc)
(parse-body body :documentation t)
`(defun ,name ,args
,@(and doc (list doc))
,@decl
(with-task ,@body))))
(defmacro with-task (&body body)
`(let ((*task-rollback* nil))
(handler-bind ((error #'%do-rollbacks))
,@body)))
(defun %do-rollbacks (c)
(declare (ignore c))
(mapcar #'funcall *task-rollback*)
nil)
#+(or)
(define-task my-task ()
(with-step "step one"
(ensure nil)
(using nil)))
#+(or)
(my-task)