Skip to content

Commit

Permalink
Check schedule working hour in Clojure where timezone is known
Browse files Browse the repository at this point in the history
  • Loading branch information
mdemare committed Jun 13, 2024
1 parent 31a0129 commit 9060d90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-rio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Check if RIO queue is up or down

on:
schedule:
- cron: '6 7-15 * * 1-5' # every hour on weekdays during working hours
- cron: '6 7-18 * * 1-5' # every hour on weekdays during working hours. Code will to a timezone check.

jobs:
riotest:
Expand Down Expand Up @@ -54,4 +54,4 @@ jobs:
TOKEN_ENDPOINT: ${{ secrets.TOKEN_ENDPOINT }}
TRUSTSTORE: truststore.jks
TRUSTSTORE_PASSWORD: ${{ secrets.TRUSTSTORE_PASSWORD }}
run: lein mapper test-rio rio-mapper-dev.jomco.nl
run: lein mapper test-rio rio-mapper-dev.jomco.nl cron
36 changes: 20 additions & 16 deletions src/nl/surf/eduhub_rio_mapper/cli_commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
[nl.surf.eduhub-rio-mapper.specs.ooapi :as ooapi]
[nl.surf.eduhub-rio-mapper.specs.rio :as rio]
[nl.surf.eduhub-rio-mapper.worker :as worker])
(:import [java.util UUID]))
(:import [java.time LocalTime]
[java.util UUID]))

(defn- parse-getter-args [[type id & [pagina]]]
{:pre [type id (string? type)]}
Expand Down Expand Up @@ -73,28 +74,31 @@
(worker/start-worker! config)))

"test-rio"
(let [[client-info _] (parse-client-info-args args clients)
(let [[client-info args] (parse-client-info-args args clients)
cron (= "cron" (first args))
working (< 9 (.getHour (LocalTime/now)) 17) ; only run between 9:00 and 17:00 local time
uuid (UUID/randomUUID)
eduspec (-> "../test/fixtures/ooapi/education-specification-template.json"
io/resource
slurp
(json/read-str :key-fn keyword)
(assoc :educationSpecificationId uuid))]

(try
(insert! {:institution-oin (:institution-oin client-info)
:institution-schac-home (:institution-schac-home client-info)
::ooapi/type "education-specification"
::ooapi/id uuid
::ooapi/entity eduspec})
(println "The RIO Queue is UP")
(catch Exception ex
(when-let [ex-data (ex-data ex)]
(when (= :down (:rio-queue-status ex-data))
(println "The RIO Queue is DOWN")
(System/exit -1)))
(println "An unexpected exception has occurred: " ex)
(System/exit -2))))
(when (or working (not cron))
(try
(insert! {:institution-oin (:institution-oin client-info)
:institution-schac-home (:institution-schac-home client-info)
::ooapi/type "education-specification"
::ooapi/id uuid
::ooapi/entity eduspec})
(println "The RIO Queue is UP")
(catch Exception ex
(when-let [ex-data (ex-data ex)]
(when (= :down (:rio-queue-status ex-data))
(println "The RIO Queue is DOWN")
(System/exit -1)))
(println "An unexpected exception has occurred: " ex)
(System/exit -2)))))

"get"
(let [[client-info rest-args] (parse-client-info-args args clients)]
Expand Down

0 comments on commit 9060d90

Please sign in to comment.