Browse code
Separate watching the stack from displaying info about it
Ed Langley authored on 14/04/2018 07:06:27
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -45,7 +45,8 @@ |
45 | 45 |
|
46 | 46 |
(defun every-five-seconds (cb args &optional (delay-function #'sleep)) |
47 | 47 |
(loop |
48 |
- while (apply cb args) |
|
48 |
+ for (continue? . next-args) = (multiple-value-list (apply cb args)) then (multiple-value-list (apply cb next-args)) |
|
49 |
+ while continue? |
|
49 | 50 |
do (funcall delay-function 5))) |
50 | 51 |
|
51 | 52 |
(deftest every-five-seconds () |
... | ... |
@@ -58,35 +59,59 @@ |
58 | 59 |
(< counter 10))) |
59 | 60 |
(every-five-seconds #'work () #'fake-delay) |
60 | 61 |
(should be = 10 counter) |
62 |
+ (should be = 5 delay))) |
|
63 |
+ |
|
64 |
+ (let (delay |
|
65 |
+ (count 0) |
|
66 |
+ (counters ())) |
|
67 |
+ (flet ((fake-delay (num) |
|
68 |
+ (setf delay num)) |
|
69 |
+ (work (counter) |
|
70 |
+ ;; temporary for initial red... |
|
71 |
+ (if (> count 10) |
|
72 |
+ (throw 'quit nil) |
|
73 |
+ (incf count)) |
|
74 |
+ |
|
75 |
+ (push counter counters) |
|
76 |
+ (values (< counter 10) |
|
77 |
+ (1+ counter)))) |
|
78 |
+ (catch 'quit |
|
79 |
+ (every-five-seconds #'work '(0) #'fake-delay)) |
|
80 |
+ (should be equal |
|
81 |
+ (alexandria:iota 11 :start 10 :step -1) |
|
82 |
+ counters) |
|
61 | 83 |
(should be = 5 delay)))) |
62 | 84 |
|
63 |
-(defclass stack-watcher () |
|
64 |
- ()) |
|
85 |
+(defun parameter-block (the-stack) |
|
86 |
+ (format t "~& PARAMETERS ~%============~%") |
|
87 |
+ (stack-parameters the-stack) |
|
88 |
+ (format t "~&============~2%")) |
|
89 |
+ |
|
90 |
+(defun output-block (the-stack) |
|
91 |
+ (format t "~2& OUTPUTS ~%=========~%") |
|
92 |
+ (stack-outputs the-stack) |
|
93 |
+ (format t "~&=========~%") |
|
94 |
+ (values)) |
|
95 |
+ |
|
96 |
+(defun stack-info (the-stack) |
|
97 |
+ (lambda (old-status) |
|
98 |
+ (unless old-status |
|
99 |
+ (parameter-block the-stack)) |
|
100 |
+ |
|
101 |
+ (let ((current-status (stack-status the-stack))) |
|
102 |
+ (unless (eql old-status current-status) |
|
103 |
+ (format t "~&STATUS ~a~%" current-status) |
|
104 |
+ (setf old-status current-status)) |
|
105 |
+ |
|
106 |
+ (values (if (ends-with-subseq "COMPLETE" (symbol-name current-status)) |
|
107 |
+ (output-block the-stack) |
|
108 |
+ t) |
|
109 |
+ current-status)))) |
|
65 | 110 |
|
66 | 111 |
(defun watch-stack (name) |
67 |
- (format t "~&Watching ~s~2%" name) |
|
68 |
- (block nil |
|
69 |
- (let ((old-status nil)) |
|
70 |
- (every-five-seconds |
|
71 |
- (lambda () |
|
72 |
- (let* ((the-stack (stack-for-name name)) |
|
73 |
- (current-status (stack-status the-stack))) |
|
74 |
- (unless old-status |
|
75 |
- (format t "~& PARAMETERS ~%============~%") |
|
76 |
- (stack-parameters the-stack) |
|
77 |
- (format t "~&============~2%")) |
|
78 |
- |
|
79 |
- (unless (eql old-status current-status) |
|
80 |
- (format t "~&STATUS ~a~%" current-status) |
|
81 |
- (setf old-status current-status)) |
|
82 |
- |
|
83 |
- (if (ends-with-subseq "COMPLETE" (symbol-name current-status)) |
|
84 |
- (progn |
|
85 |
- (format t "~2& OUTPUTS ~%=========~%") |
|
86 |
- (stack-outputs the-stack) |
|
87 |
- (format t "~&=========~%") |
|
88 |
- nil) |
|
89 |
- t))) |
|
90 |
- ()))) |
|
91 |
- (fresh-line)) |
|
112 |
+ (let ((the-stack (stack-for-name name))) |
|
113 |
+ (format t "~&Watching ~s~2%" name) |
|
114 |
+ (every-five-seconds (stack-info the-stack) |
|
115 |
+ (list nil)) |
|
116 |
+ (fresh-line))) |
|
92 | 117 |
|