Browse code
Separating staleness checking from stack display
Ed Langley authored on 14/04/2018 08:02:06
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -93,24 +93,53 @@ |
93 | 93 |
(format t "~&=========~%") |
94 | 94 |
(values)) |
95 | 95 |
|
96 |
-(defun stack-info (name old-status) |
|
97 |
- (let* ((the-stack (stack-for-name name)) |
|
98 |
- (current-status (stack-status the-stack))) |
|
99 |
- (unless old-status |
|
100 |
- (parameter-block the-stack)) |
|
101 |
- |
|
102 |
- (unless (equal old-status current-status) |
|
103 |
- (format t "~&STATUS ~a~%" old-status current-status)) |
|
104 |
- |
|
105 |
- (values (if (ends-with-subseq "COMPLETE" (symbol-name current-status)) |
|
106 |
- (output-block the-stack) |
|
107 |
- t) |
|
108 |
- name |
|
109 |
- current-status))) |
|
96 |
+(defclass stack-formatter () |
|
97 |
+ ((%stack :initarg :stack :accessor stack) |
|
98 |
+ (%old-status :initarg :old-status :accessor old-status :initform nil))) |
|
99 |
+ |
|
100 |
+(defmethod stack-status ((stack-formatter stack-formatter)) |
|
101 |
+ (when (slot-boundp stack-formatter '%stack) |
|
102 |
+ (stack-status (stack stack-formatter)))) |
|
103 |
+ |
|
104 |
+(defmethod parameters ((stack-formatter stack-formatter)) |
|
105 |
+ (when (slot-boundp stack-formatter '%stack) |
|
106 |
+ (parameters (stack stack-formatter)))) |
|
107 |
+ |
|
108 |
+(defmethod outputs ((stack-formatter stack-formatter)) |
|
109 |
+ (when (slot-boundp stack-formatter '%stack) |
|
110 |
+ (outputs (stack stack-formatter)))) |
|
111 |
+ |
|
112 |
+(defmethod (setf stack) :before (new-value (object stack-formatter)) |
|
113 |
+ (setf (old-status object) (stack-status object))) |
|
114 |
+ |
|
115 |
+(defgeneric refresh-stack (stack-formatter) |
|
116 |
+ (:method ((stack cloud-watcher.aws-result:stack)) |
|
117 |
+ (stack-for-name (stack-name stack))) |
|
118 |
+ (:method ((stack-formatter string)) |
|
119 |
+ (make-instance 'stack-formatter :stack (stack-for-name stack-formatter))) |
|
120 |
+ (:method ((stack-formatter stack-formatter)) |
|
121 |
+ (setf (stack stack-formatter) (refresh-stack (stack stack-formatter))) |
|
122 |
+ stack-formatter)) |
|
123 |
+ |
|
124 |
+(defun stack-info (the-stack) |
|
125 |
+ (with-accessors ((old-status old-status)) the-stack |
|
126 |
+ (let* ((current-status (stack-status the-stack))) |
|
127 |
+ (unless old-status |
|
128 |
+ (parameter-block the-stack)) |
|
129 |
+ |
|
130 |
+ (unless (equal old-status current-status) |
|
131 |
+ (format t "~&STATUS ~a~%" current-status)) |
|
132 |
+ |
|
133 |
+ (if (ends-with-subseq "COMPLETE" (symbol-name current-status)) |
|
134 |
+ (output-block the-stack) |
|
135 |
+ t)))) |
|
110 | 136 |
|
111 | 137 |
(defun watch-stack (name) |
112 | 138 |
(format t "~&Watching ~s~2%" name) |
113 |
- (every-five-seconds 'stack-info |
|
114 |
- (list name nil)) |
|
139 |
+ (every-five-seconds (lambda (stale-stack) |
|
140 |
+ (let ((the-stack (refresh-stack stale-stack))) |
|
141 |
+ (values (stack-info the-stack) |
|
142 |
+ the-stack))) |
|
143 |
+ (list name)) |
|
115 | 144 |
(fresh-line)) |
116 | 145 |
|