Selaa lähdekoodia

Main loop in thread, explicit timer creation

Innocenty Enikeew 10 vuotta sitten
vanhempi
commit
9514fad16c
2 muutettua tiedostoa jossa 12 lisäystä ja 17 poistoa
  1. 1 0
      chatikbot.asd
  2. 11 17
      chatikbot.lisp

+ 1 - 0
chatikbot.asd

@@ -4,6 +4,7 @@
   :author "Innokentiy Enikeev <me@enikesha.net>"
   :license "MIT"
   :depends-on (#:alexandria
+               #:bordeaux-threads
                #:cl-oauth
                #:clon
                #:flexi-streams

+ 11 - 17
chatikbot.lisp

@@ -89,22 +89,16 @@
                                :disable-web-preview 1)))
 
 
-(defvar *crons* (list
-                 (list #'process-latest-akb '(:minute * :hour *)))
-  "List of cron functions with their schedules")
-(defvar *cron-timers* nil)
-
 (defun start ()
   (mapc #'sb-ext:unschedule-timer (trivial-timers:list-all-timers))
-  (setf *cron-timers*
-        (loop for (function schedule) in *crons*
-           do (log:info "Starting cron" function schedule)
-           collect
-             (clon:schedule-function
-              (lambda () (funcall function))
-              (clon:make-scheduler
-               (apply #'clon:make-typed-cron-schedule schedule)
-               :allow-now-p t)
-              :thread t)))
-  (loop
-       do (process-updates)))
+  (clon:schedule-function
+   (lambda () (process-latest-akb))
+   (clon:make-scheduler
+    (clon:make-typed-cron-schedule :minute '* :hour '*)
+    :allow-now-p t)
+   :thread t)
+  (bordeaux-threads:make-thread
+   (lambda ()
+     (loop
+        do (process-updates)))
+   :name "process-updates"))