|
@@ -28,21 +28,27 @@
|
|
|
|
|
|
|
|
(defmethod restas:initialize-module-instance :before ((module (eql #.*package*)) context)
|
|
(defmethod restas:initialize-module-instance :before ((module (eql #.*package*)) context)
|
|
|
(restas:with-context context
|
|
(restas:with-context context
|
|
|
- (alexandria:when-let (file (probe-file "config.lisp"))
|
|
|
|
|
|
|
+ (alexandria:when-let (file (probe-file
|
|
|
|
|
+ (merge-pathnames "src/config.lisp"
|
|
|
|
|
+ (asdf:component-pathname
|
|
|
|
|
+ (asdf:find-system '#:timeliner)))))
|
|
|
(load file))
|
|
(load file))
|
|
|
- (cl-mongo:mongo :host *mongo-host*)
|
|
|
|
|
- (cl-mongo:db.use *mongo-db*)
|
|
|
|
|
(when *run-cron*
|
|
(when *run-cron*
|
|
|
(restas:context-add-variable
|
|
(restas:context-add-variable
|
|
|
context '*cron-timers*
|
|
context '*cron-timers*
|
|
|
(loop for (function schedule) in *crons*
|
|
(loop for (function schedule) in *crons*
|
|
|
do (log:info "Starting cron" function schedule)
|
|
do (log:info "Starting cron" function schedule)
|
|
|
collect
|
|
collect
|
|
|
- (clon:schedule-function function
|
|
|
|
|
- (clon:make-scheduler
|
|
|
|
|
- (apply #'clon:make-typed-cron-schedule schedule)
|
|
|
|
|
- :allow-now-p t)
|
|
|
|
|
- :thread t))))))
|
|
|
|
|
|
|
+ (clon:schedule-function
|
|
|
|
|
+ (let ((f function))
|
|
|
|
|
+ (lambda ()
|
|
|
|
|
+ (let ((cl-mongo::*mongo-registry* nil)) ;; make connections thread-local
|
|
|
|
|
+ (cl-mongo:with-mongo-connection (:host *mongo-host* :db *mongo-db*)
|
|
|
|
|
+ (funcall f)))))
|
|
|
|
|
+ (clon:make-scheduler
|
|
|
|
|
+ (apply #'clon:make-typed-cron-schedule schedule)
|
|
|
|
|
+ :allow-now-p t)
|
|
|
|
|
+ :thread t))))))
|
|
|
|
|
|
|
|
(defmethod restas:finalize-module-instance :after ((module (eql #.*package*)) context)
|
|
(defmethod restas:finalize-module-instance :after ((module (eql #.*package*)) context)
|
|
|
(let ((timers (restas:context-symbol-value context '*cron-timers*)))
|
|
(let ((timers (restas:context-symbol-value context '*cron-timers*)))
|
|
@@ -187,16 +193,18 @@
|
|
|
(end (or (ignore-errors (ms->ts (parse-integer (hunchentoot:get-parameter "end"))))
|
|
(end (or (ignore-errors (ms->ts (parse-integer (hunchentoot:get-parameter "end"))))
|
|
|
(local-time:timestamp+ start 1 :day))))
|
|
(local-time:timestamp+ start 1 :day))))
|
|
|
(with-output-to-string (stream)
|
|
(with-output-to-string (stream)
|
|
|
- (yason:encode
|
|
|
|
|
- (cl-mongo:docs
|
|
|
|
|
- (cl-mongo:db.sort "events" ($between "ts" start end) :field "ts" :limit 2000))
|
|
|
|
|
- stream))))
|
|
|
|
|
|
|
+ (cl-mongo:with-mongo-connection (:host *mongo-host* :db *mongo-db*)
|
|
|
|
|
+ (yason:encode
|
|
|
|
|
+ (cl-mongo:docs
|
|
|
|
|
+ (cl-mongo:db.sort "events" ($between "ts" start end) :field "ts" :limit 2000))
|
|
|
|
|
+ stream)))))
|
|
|
|
|
|
|
|
(restas:define-route api/events/delete ("api/events/:id"
|
|
(restas:define-route api/events/delete ("api/events/:id"
|
|
|
:method :DELETE
|
|
:method :DELETE
|
|
|
:content-type "application/json")
|
|
:content-type "application/json")
|
|
|
- (cl-mongo:db.delete "events" (cl-mongo:$ "_id" (cl-mongo::make-bson-oid
|
|
|
|
|
- :oid (crypto:hex-string-to-byte-array id))))
|
|
|
|
|
|
|
+ (cl-mongo:with-mongo-connection (:host *mongo-host* :db *mongo-db*)
|
|
|
|
|
+ (cl-mongo:db.delete "events" (cl-mongo:$ "_id" (cl-mongo::make-bson-oid
|
|
|
|
|
+ :oid (crypto:hex-string-to-byte-array id)))))
|
|
|
"OK")
|
|
"OK")
|
|
|
|
|
|
|
|
(defparameter +timeliner.css+
|
|
(defparameter +timeliner.css+
|