From 1c99b2592e65f75ee38a74f7fd0dc8465c4211e1 Mon Sep 17 00:00:00 2001 From: Ivar Refsdal Date: Wed, 29 Jun 2022 09:08:09 +0200 Subject: Release 0.2.57 Add get-errors and retry-one-error! as well as improve unhealthy? --- README.md | 9 +++++++++ pom.xml | 4 ++-- src/com/github/ivarref/yoltq.clj | 33 ++++++++++++++++++++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ead585..c62328c 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,15 @@ easier. ## Change log +#### 2022-06-29 v0.2.57 [diff](https://github.com/ivarref/yoltq/compare/v0.2.56...v0.2.57) +Added `(get-errors qname)` and `(retry-one-error! qname)`. + +Improved: +`unhealthy?` will return `false` for the first 10 minutes of the application lifetime. +This was done in order to push new code while a queue was in error in an earlier +version of the code. In this way rolling upgrades are possible regardless if there +are queue errors. + #### 2022-06-22 v0.2.56 [diff](https://github.com/ivarref/yoltq/compare/v0.2.55...v0.2.56) Added support for `:yoltq/queue-id` metadata on functions. I.e. it's possible to write the following: diff --git a/pom.xml b/pom.xml index c45ccd9..2d992c9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ jar com.github.ivarref yoltq - 0.2.56 + 0.2.57 yoltq @@ -30,7 +30,7 @@ scm:git:git://github.com/ivarref/yoltq.git scm:git:ssh://git@github.com/ivarref/yoltq.git - v0.2.56 + v0.2.57 https://github.com/ivarref/yoltq \ No newline at end of file diff --git a/src/com/github/ivarref/yoltq.clj b/src/com/github/ivarref/yoltq.clj index ba27d2c..f4c2bf7 100644 --- a/src/com/github/ivarref/yoltq.clj +++ b/src/com/github/ivarref/yoltq.clj @@ -10,7 +10,8 @@ [datomic.api :as d]) (:import (datomic Connection) (java.time Duration) - (java.util.concurrent ExecutorService Executors TimeUnit))) + (java.util.concurrent ExecutorService Executors TimeUnit) + (java.lang.management ManagementFactory))) (defonce ^:dynamic *config* (atom nil)) @@ -168,12 +169,14 @@ (defn healthy? [] - (some->> @*config* - :healthy? - (deref))) + (or + (< (.toMinutes (Duration/ofMillis (.getUptime (ManagementFactory/getRuntimeMXBean)))) 10) + (some->> @*config* + :healthy? + (deref)))) (defn unhealthy? - "Returns `true` if there are queues in error, otherwise `false`." + "Returns `true` if there are queues in error and application has been up for over 10 minutes, otherwise `false`." [] (false? (healthy?))) @@ -198,6 +201,26 @@ (sort-by (juxt :qname :status)) (vec)))) +(defn get-errors [qname] + (let [{:keys [conn]} @*config* + db (d/db conn)] + (->> (d/q '[:find [?id ...] + :in $ ?qname ?status + :where + [?e :com.github.ivarref.yoltq/queue-name ?qname] + [?e :com.github.ivarref.yoltq/status ?status] + [?e :com.github.ivarref.yoltq/id ?id]] + db + qname + :error) + (mapv (partial u/get-queue-item db))))) + +(defn retry-one-error! [qname] + (let [{:keys [handlers] :as cfg} @*config* + _ (assert (contains? handlers qname) "Queue not found") + cfg (assoc-in cfg [:handlers qname :max-retries] Integer/MAX_VALUE)] + (poller/poll-once! cfg qname :error))) + (comment (do (require 'com.github.ivarref.yoltq.log-init) -- cgit v1.2.3