I'm attempting to create a macro similar to the Quartzite defjob macro that creates the Job class with the @DisallowConcurrentExecution annotation added to it. The code works from the repl, but not inside the macro.
This works...
user=> (defrecord ^{DisallowConcurrentExecution true} YYY []
#_=> org.quartz.Job
#_=> (execute [this context]
#_=> (println "whoosh!")))
user.YYY
user=> (seq (.getAnnotations YYY))
(#<$Proxy3 @org.quartz.DisallowConcurrentExecution()>)
...but this does not.
(defmacro defncjob
[jtype args & body]
`(defrecord ^{DisallowConcurrentExecution true} ~jtype []
org.quartz.Job
(execute [this ~@args]
~@body)))
After Rodrigo's suggestion, here is a way to make it work.
(defmacro defdcejob
[jtype args & body]
`(defrecord ~(vary-meta jtype assoc `DisallowConcurrentExecution true) []
org.quartz.Job
(execute [this ~@args]
~@body)))
You can't use the ^
reader macro inside macros. Take a look at this similar question.