Kaynağa Gözat

save-settings lock and serie sorting

Innokenty Enikev 10 yıl önce
ebeveyn
işleme
1bb345a415
2 değiştirilmiş dosya ile 23 ekleme ve 19 silme
  1. 19 16
      chatikbot.lisp
  2. 4 3
      finance.lisp

+ 19 - 16
chatikbot.lisp

@@ -437,23 +437,26 @@
      collect (cons chat-id (mapcar #'feed-url feeds))))
 
 
+(defvar *save-settings-lock* (bordeaux-threads:make-lock "save-settings-lock")
+  "Lock for multithreading access to write settings file")
 (defun save-settings()
-  (with-open-file (s (merge-pathnames "settings.lisp"
-                                      (asdf:component-pathname
-                                       (asdf:find-system '#:chatikbot)))
-                     :direction :output
-                     :if-exists :supersede
-                     :if-does-not-exist :create)
-    (write '(in-package #:chatikbot) :stream s)
-    (write
-     `(setf *fsq-send-to* (alexandria:alist-hash-table ',(alexandria:hash-table-alist *fsq-send-to*))
-            *chat-locations* ',*chat-locations*
-            *akb-send-to* ',*akb-send-to*
-            *akb-last-id* ,*akb-last-id*
-            *rss-chat-feeds* (%load-rss-feeds ',(%save-rss-feeds))
-            *per-minute-rates* (make-circular ',(flat-circular *per-minute-rates*)))
-     :stream s)
-    (values)))
+  (bordeaux-threads:with-lock-held (*save-settings-lock*)
+    (with-open-file (s (merge-pathnames "settings.lisp"
+                                        (asdf:component-pathname
+                                         (asdf:find-system '#:chatikbot)))
+                       :direction :output
+                       :if-exists :supersede
+                       :if-does-not-exist :create)
+      (write '(in-package #:chatikbot) :stream s)
+      (write
+       `(setf *fsq-send-to* (alexandria:alist-hash-table ',(alexandria:hash-table-alist *fsq-send-to*))
+              *chat-locations* ',*chat-locations*
+              *akb-send-to* ',*akb-send-to*
+              *akb-last-id* ,*akb-last-id*
+              *rss-chat-feeds* (%load-rss-feeds ',(%save-rss-feeds))
+              *per-minute-rates* (make-circular ',(flat-circular *per-minute-rates*)))
+       :stream s)
+      (values))))
 
 (defun start ()
   ;; Clear prev threads

+ 4 - 3
finance.lisp

@@ -28,9 +28,10 @@
     (error (e) (log:error e))))
 
 (defun get-serie (series name)
-  (loop for (time . rates) in series
-     when (numberp (aget name rates))
-     collect (list time (aget name rates))))
+  (sort (loop for (time . rates) in series
+           when (numberp (aget name rates))
+           collect (list time (aget name rates)))
+        #'> :key #'car))
 
 (defun make-chart (series &key (usd t) (eur t) (gbp t) (brent t))
   (let ((flat (remove-if #'null (if (alexandria:circular-list-p series)