I have an API post route that takes in some information from the user.
The API is built with Common Lisp. When the form is submitted, I would like to "wait" for 24 hours to execute a function.
So, a sort of scheduler for execution.
I looked at cl-cron
, but I only want this to execute one time at a variable date that i can specify manually.
How can I create this for a long running lisp image?
;; note - defroute is part of easy-routes library
(defroute post-route ("api/post/route" :method :post) (&post name email)
(validation-function ...)
(save-to-db ....)
(do-something ...) ;; < -- these 3 are implemented
(schedule-future-action firstname email seconds-in-future) ;; <--- not implemented
(redirect ...) < -- implemented
)
I created a solution based on coredump's comment.
I built a priority queue data structure that keeps a record of events. The queue is saved on the local file system. It is sorted by the time stamp of the event (which depends on user action).
When the controller activates, actions get saved and sorted into the queue.
Finally, a second thread, runs cl-cron. Which runs a function every 1 minute. It reads the first item in the priority queue, if ready executes and delete item. if not do nothing.
The important part is, as coredump suggested, if the lisp image crashes for whatever reason, the cron job can continue where it left off.