(values-list retn))))
(defun start-shutdown-thread ()
+ (format t "Starting AWS shutdown thread~%")
(sb-thread:make-thread
(lambda ()
(loop
(sleep 30)))
:name "AWS Shutdown Thread"))
+(defmethod candle:shutdown-system ((job-system (eql :aws)))
+ (format t "Shutting down AWS box for exit~%")
+ ; If there's a job going, we need to wait for it to finish
+ (sb-thread:with-mutex (*aws-mutex*))
+ (stop-aws-box))
+
(defun aws-command (cmd &rest args)
(with-output-to-string (out)
(sb-ext:run-program
:error out-str
:wait t)))))
(values (zerop code) out)))
+
+; NOOP as there is no service that needs to be cleaned up
+(defmethod candle:shutdown-system ((job-system (eql :local))))
(:export
#:server #:add-project #:delete-project #:refresh-project #:list-projects
#:project-branch-information #:run #:*candle-dir* #:*job-system* #:*candle-dir* #:failures
- #:project-job-information #:get-job-log #:retry-job #:job-project #:project-dir #:process-job-in-system))
+ #:project-job-information #:get-job-log #:retry-job #:job-project #:project-dir #:process-job-in-system
+ #:shutdown-system))
(defpackage #:candle-cli (:use :cl) (:export :run))
(defpackage #:candle-aws (:use :cl))
(defvar *job-system*)
(defgeneric process-job-in-system (job-system job))
+(defgeneric shutdown-system (job-system))
(defun start-processor-thread ()
- (sb-thread:make-thread
- (lambda ()
- (loop
- (let
- ((job (find :queued *all-job* :key #'job-status)))
- (if job
- (process-job job)
- ; We just wait here until the processor is released, which is usually done
- ; when a project is refreshed.
- (sb-thread:with-mutex (*mutex*)
- (sb-thread:condition-wait *waitq* *mutex*))))))
- :name "Processor"))
+ (format t "Starting processor in ~(~A~) mode~%" *job-system*)
+ (let*
+ ((active t)
+ (processor-thread
+ (sb-thread:make-thread
+ (lambda ()
+ (loop
+ :while active
+ :do
+ (let
+ ((job (find :queued *all-job* :key #'job-status)))
+ (if job
+ (process-job job)
+ ; We just wait here until the processor is released, which is usually done
+ ; when a project is refreshed.
+ (sb-thread:with-mutex (*mutex*)
+ (sb-thread:condition-wait *waitq* *mutex*))))))
+ :name "Processor")))
+ (push
+ (lambda ()
+ (format t "Shutting down processor thread~%")
+ (setf active nil)
+ (awaken-processor-thread)
+ (sb-thread:join-thread processor-thread)
+ (shutdown-system *job-system*))
+ sb-ext:*exit-hooks*)))
(defun awaken-processor-thread ()
(sb-thread:with-mutex (*mutex*)
(defun server (port &optional (background t))
(when (not *candle-dir*) (error "Need a candle dir"))
- (let
+ (let*
((data-dir (format nil "~Adata" *candle-dir*)))
(ensure-directories-exist *candle-dir*)
(ensure-directories-exist data-dir)
(lame-db:load-known-dbs data-dir)
- (sb-thread:make-thread
- (lambda ()
- (do () (nil)
- (progn
- (sleep (* 5 60))
- (lame-db:save-known-dbs data-dir))))
- :name "Save Thread")
(format t "Starting processor in ~(~A~) mode~%" *job-system*)
+ (start-save-thread data-dir)
(start-processor-thread)
(communication:start-listener port background)))
+(defun start-save-thread (data-dir)
+ (format t "Starting Save Thread~%")
+ (let*
+ ((mutex (sb-thread:make-mutex))
+ (waitq (sb-thread:make-waitqueue))
+ (active t)
+ (save-thread
+ (sb-thread:make-thread
+ (lambda ()
+ (loop
+ :while active
+ :do
+ (sb-thread:with-mutex (mutex)
+ (sb-thread:condition-wait waitq mutex)))
+ (lame-db:save-known-dbs data-dir))
+ :name "Save Thread")))
+ (sb-thread:make-thread
+ (lambda ()
+ (loop
+ (sleep (* 1 60))
+ (sb-thread:with-mutex (mutex)
+ (sb-thread:condition-broadcast waitq))))
+ :name "Save Thread Trigger")
+ (push
+ (lambda ()
+ (format t "Shutting down save thread~%")
+ (sb-thread:with-mutex (mutex)
+ (setf active nil)
+ (sb-thread:condition-broadcast waitq))
+ (sb-thread:join-thread save-thread))
+ sb-ext:*exit-hooks*)))
+
(defun add-project (name src)
(when
(not (cl-ppcre:scan "^[0-9A-Za-z-]*$" name))