Skip to content

Commit

Permalink
Improved rio queue test notifications (#323)
Browse files Browse the repository at this point in the history
* Moved timezone check to crontab

* Use previous status of action
  • Loading branch information
mdemare authored Jul 29, 2024
1 parent ad3c640 commit afb8b69
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/test-rio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ name: Check if RIO queue is up or down

on:
schedule:
- cron: '6 7-18 * * 1-5' # every hour on weekdays during working hours. Code will do a timezone check.
# every hour on weekdays during working hours, 9:06 tm 16:06
# may be shifted an hour in late March and October, but that's not a big deal
- cron: '6 8-15 * 1,2,3,11,12 1-5' # Winter time CET (UTC+1).
- cron: '6 7-14 * 4-10 1-5' # Summer time CET (UTC+2)

jobs:
rio_queue:
runs-on: ubuntu-latest

steps:
- name: Get status of previous run of this workflow - store in last_status
uses: Mercymeilya/last-workflow-status@v0.3.3
id: last_status

- name: Cache lein project dependencies
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -57,24 +64,26 @@ jobs:
TRUSTSTORE_PASSWORD: ${{ secrets.TRUSTSTORE_PASSWORD }}
id: test_rio
run: |
lein mapper test-rio rio-mapper-dev.jomco.nl cron
lein mapper test-rio rio-mapper-dev.jomco.nl
echo "ERROR_STATUS=$?" >> "$GITHUB_OUTPUT"
continue-on-error: true
- name: Notify ok
- name: Notify ok only if previous run failed.
env:
SLACK_URL: ${{ secrets.SLACK_URL }}
if: ${{ steps.test_rio.outputs.ERROR_STATUS == 0 }}
if: ${{ steps.test_rio.outputs.ERROR_STATUS == 0 && steps.last_status.outputs.last_status != 'success' }}
run: |
curl -q -H "Content-Type: application/json" -X POST -d '{"text": "RIO Queue is UP"}' $SLACK_URL
curl -q -H "Content-Type: application/json" -X POST -d '{"text": "RIO Queue is finally UP"}' $SLACK_URL
- name: Notify queue down
env:
SLACK_URL: ${{ secrets.SLACK_URL }}
if: ${{ steps.test_rio.outputs.ERROR_STATUS == -1 }}
run: |
curl -q -H "Content-Type: application/json" -X POST -d '{"text": "RIO Queue is DOWN"}' $SLACK_URL
exit 1
- name: Notify error
env:
SLACK_URL: ${{ secrets.SLACK_URL }}
if: ${{ steps.test_rio.outputs.ERROR_STATUS == -2 }}
run: |
curl -q -H "Content-Type: application/json" -X POST -d '{"text": "Error while checking RIO Queue"}' $SLACK_URL
exit 1
38 changes: 16 additions & 22 deletions src/nl/surf/eduhub_rio_mapper/cli_commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
[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.time LocalDateTime]
[java.util TimeZone UUID]))
(:import [java.util UUID]))

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

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

(if (and cron offline)
(println "Skipping test - not within working hours")
(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)))))
(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 afb8b69

Please sign in to comment.