Thank you for attending my Webinar.
The AllegroCache developer was watching and pointed out I misspoke a bit about with-transaction-restarts. I said it caught the error and retried its body, and suggested this:
(loop (rollback) ;; syncs local and stored (if (with-transaction-restart () (sell “jr1001” 6) (commit)) (return t)))
Actually, the loop is not necessary since with-transaction-restarts itself does a (rollback) if the commit fails, so the code above simplifies to:
(with-transaction-restart () (sell “jr1001” 6) (commit))
An initial (rollback) is not necessary since if the database value for that slot is out of sync, the commit will fail and with-transaction-restart will do the (rollback) and then re-evaluate the body. The (commit) within the body is necessary, of course.
Then our improved SELL function is:
(defun sell (perf-id number) (let* ((perf (retrieve-from-index 'performance 'perf-id perf-id))) (with-transaction-restart () (let* ((avail (perf-unsold perf)) (sold (perf-sold perf))) (if (<= number avail) (progn (setf (perf-unsold perf) (- avail number)) (setf (perf-sold perf) (+ sold number)) (commit)) (error "only ~d tickets available, cannot sell ~d" avail number))))))
The slides have been updated.
|Copyright © 2018 Franz Inc., All Rights Reserved | Privacy Statement|