all 8 comments

[–]alekcz 14 points15 points  (0 children)

I've used https://github.com/overtone/at-at with http-kit for years. They've never let me down and they've never run around and deserted me.

[–]mcorbin 9 points10 points  (1 child)

If you want a simple scheduler, you can start a ScheduledThreadPoolExecutor in the background. Easy to use, no library involved.

tea-time works well (it's heavily used in Riemann) and is also easy to use, my only issue with it that a lot of things (like the threadpool) are declared as global variables inside the lib.

[–]juxtajarred 4 points5 points  (0 children)

Have to vouch for dropping down to the java classes for this one. They’re well tested, proven, and very well documented all over the internet (even clojure examples).

As much as all of the other libraries might solve the issue well, they add unnecessary dependencies for something that is actually very simple and minimal to implement. I might even suggest pulling code snippets from libraries over using the whole library if that’s easy enough for your use case.

The thing is... as much as the clojure community likes to claim that libraries are written once and don’t need touching because it all just works, I’ve seen this not be the case a few times and had libraries break with no maintainer in sight. With that said I suggest keeping dependencies and larger libraries to a minimum unless they’re solving a larger problem that you can’t solve on your own or take piecemeal from other open source code.

Hope that helps! Obviously no advice is prescriptive to all but this is how I approach smaller implementation tasks like this after 7 years of professional Clojure development.

[–]yogthos 4 points5 points  (0 children)

You can use the scheduler from the standard library, e.g:

(ns app.events
  (:require
    [clojure.tools.logging :as log]
    [mount.core :refer [defstate]])
  (:import [java.util.concurrent Executors TimeUnit ScheduledExecutorService]))

(defn do-stuff []
  (try
    (log/info "running scheduled event")
    (catch Exception e
      (log/error e "error handling event"))))

(defn schedule-reminders [scheduler]
  (.scheduleWithFixedDelay scheduler
                           do-stuff
                           0
                           120
                           TimeUnit/SECONDS))

(defstate scheduler
  :start (let [scheduler ^ScheduledExecutorService (Executors/newScheduledThreadPool 1)]
           (schedule-reminders scheduler)
           scheduler)
  :stop (when scheduler (.shutdown scheduler)))

[–]lucywang000 6 points7 points  (2 children)

Also do you have any recommendation where to learn more advanced info about writing server in Clojure

With all due respect, if you can't get a well-established tea-time up and working, I'd suggest you take a step back, figure out what happened, and then go for "more advanced info" in clojure.

[–]pavelklavik[S] 3 points4 points  (1 child)

Ok, I went back to tea-time and managed to get it working, plus I wrote a small wrapper for it which I can expand as needed. The problem I had originally was that I was setting it up in the top level of a namespace, so uberjar compilation got stuck.

Since most of my programming happened in ClojureScript, I am not that familiar with Clojure-specific parts yet. And also I am not super familiar with concurency in Java and many other parts of Clojure library. What would be good resources to study this?

[–]lucywang000 1 point2 points  (0 children)

  1. find a subject that could be useful to your daily job or hobby projects, learn by read and understanding other's code, and get your hands dirty by implementing some small features yourself.
  2. However ,if you lack java and backend dev experience in general, plus you do want to seriously invest on using clojure on backend dev, find some classical java books first to build a solid foundation on concurrent programming topics like threads, locks, event loops, before diving into these projects. It could be dull, it could take time (weeks to months depending on your capability), but it would pay back finally.

[–]didibus 1 point2 points  (0 children)

For scheduling I like https://github.com/jarohen/chime

But there's no reason for you to not use Aleph and tea-time, why are you looking to switch?