Clojure daemon

Hi all, I’m currently searching how to make a daemon application which will start a scheduler in background and schedule things from time to time. I was wondering what was the clojure way for doing it. I don’t have much experience with JVm so this is why I am asking for. In the web I found this Is this example the recommended way? Tia

1 Like

So i’m thinking todo following:

  1. using a watcher to watch files (conf) l
  2. using infinite loop like this: (in main)
  (loop []
    (println "doing things")
     .. do stuff

i’m overseeing something if i will do like this?

I’m familiar with JavaScript, I would use ClojureScript… not JVM though…

  (fn [] (println "do something"))

Compile it to JavaScript and run in background with pm2.

Not familiar with Java, but you might need to look into core.async

1 Like

How robust you want it to be? If very robust, use quartz.

1 Like

Thx didibjs. Can you redifine robustness (resliance or fault toleration) ? Afaik quartz is a scheduler for jobs. I’m curious about how can fit as a daemon. OK the scheduler run as daemon but why one should pick it up? Thx

This code snippet suggests that you haven’t really written any clojure (calling def inside a loop is a big red flag). Would you consider giving a use case and maybe telling us why you want to do it with clojure in particular?

1 Like

HI Jack, thanks for the remark. I have fixed the snippet meanwhile. ( and it was only intended to showcase the infinite loop, although i know that def is a bad thing to call it in defn, it was a mental typo).

I’m searching for doing a a simple daemon as design pattern, and yes i’m a happy beginner at clojure language :slight_smile:

Why i want to use clojure in general? Yes i could use other language but i want to explore Clojure/Lisp and i think the language is cool enough to learn as intellectual activity and as developer.

The “initial use case” would be the main process sleeping and doing some tasks in a regular time ( without any custom library). The motivation is personal curiosity also

So i was wondering if in JVM env. having an infinite loop like i posted is something acceptable or there are clever way to do do it in the platform. But for that thx to @jiyinyiyong i have at least the core-async hint to read and discover

Ok, that’s helpful! @didibus’s suggestion was good if you wanted to be practical and get something into production, but it sounds like what you want is to experiment and learn things. For that, starting with something like what’s in the Cookbook would be fine. You also mention watching files, for which there are some libraries (hawk, dirwatch, and so on).

(BTW, “process sleeping and doing some tasks in a regular time” isn’t a use case. “Check every two minutes whether the birdfeeder in my garden is empty and send me an email if it is” is a use case.)

1 Like

Jack thx for your precision! You are perfectly right, doing some tasks etc isn’t precise as you stated.

I perfectly agree with you with

Thx for the links!

My initial question was since for me JVM is kind of blackbox, i was thinking if the JVM wouldn’t kill some process which are doing noop or doing some fancy operation… but i think that is not the case.

Anyways thx for all response it helped me ! :sunny:

When you schedule jobs, there’s more that can go wrong than one thinks. For example, what about overlapping jobs? What if a job fails? What if the previous job hasn’t finished yet, but it’s time to start the next one already? Etc.

A system that can handle these scenarios gracefully is more robust. That’s what I meant by robustness in this case.

I’m also wondering what do you mean by daemon? Are you asking for a Windows service compatible process? Or do you just want a long running process?


Yes i want a long running process.

My idea was to have a process in background, which check/watch a file (the input db.edn) every xx min and if there is new events it will add the jobs needed.

I’m using now quarzite now ( after trying other libs). Looks really cool. (thx @didibus for suggestion)
One thing i have found that quarzite clojure library looks not maintained at moment.

( I can fully understand that somebody created it and now want to do other things. I’m also opensource maintainer for other projects.)

From your pov should we create a new thread for discussing the quarzite library, maintainance? to me i would at least update it to latest quartz and maybe if i need i would add other calls if i need them.

I was also interested how we can find new maintainers to old lib for a period of time.

Here’s a link to Procrun if you need a windows service

This project was helpful for me to understand what a windows batch .bat would look like for install time:

I noticed apache ActiveMQ is bundled with the 32-bit version (free) of this solution (again windows services).

1 Like

Hi @MalloZup, I am also doing a daemon application, that pull data from a database and push it to a queue, I am using to schedule, it is running very well.


Regarding file watching, I found helpful figwheel-main code (it uses Hawk) –

1 Like

thx to all. I have just released the 0.0.1 version

for any suggestion feel free to drop an issue always appreciated! :rocket:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.