Skip to content

Commit

Permalink
add some logging to song sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramblurr committed Nov 20, 2023
1 parent b70da95 commit 17d73f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/clj/app/cms.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
(ns app.cms
(:require
[clojure.tools.logging :as log]
[app.errors :as errors]
[jsonista.core :as j]
[org.httpkit.client :as client]
[app.queries :as q]
[datomic.client.api :as datomic]
[tick.core :as t]))


(defn update-cms-req [cms-url token payload]
{:method :post
:url (str cms-url "/api/song/")
Expand All @@ -26,15 +26,16 @@
:arrangement_notes arrangement-notes
:last_played_date (when last-played-on (-> last-played-on t/date-time str))})


(defn sync-song! [{:keys [db] :as system} song-id]
(try
(let [
{:keys [token cms-url]} (-> system :env :cms)
song (q/retrieve-song db song-id)]
@(client/request (->> song
song->wagtail
(update-cms-req cms-url token))))
(let [{:keys [token cms-url]} (-> system :env :cms)
song (q/retrieve-song db song-id)
resp @(client/request (->> song
song->wagtail
(update-cms-req cms-url token)))]
(log/info (str "synced with cms song-id=" song-id))
(log/info resp)
resp)
(catch Exception e
(errors/report-error! e))))

Expand All @@ -52,5 +53,4 @@
@(client/request req)))]
resp)
(catch Exception e
(errors/report-error! e))
))
(errors/report-error! e))))
2 changes: 2 additions & 0 deletions src/clj/app/jobs/gig_events.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns app.jobs.gig-events
(:require
[clojure.tools.logging :as log]
[app.cms :as cms]
[app.caldav :as caldav]
[app.discourse :as discourse]
Expand Down Expand Up @@ -72,6 +73,7 @@
(exec-later handle-gig-created req notify? thread? gig-id))

(defn handle-song-edited [req song-id]
(log/info (str "handle-song-edited song-id=" song-id))
(cms/sync-song! (update-system req) song-id))

(defn trigger-song-edited
Expand Down
6 changes: 5 additions & 1 deletion src/clj/app/jobs/sync_songs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
[datomic.client.api :as datomic]
[ol.jobs-util :as jobs]))

(defn song-sync-job [system _]
(cms/sync-all-songs! system))

(defn make-songs-sync-job [system]
(fn [{:job/keys [frequency initial-delay]}]
(jobs/make-repeating-job (partial #'cms/sync-all-songs! system) frequency initial-delay)))
(jobs/make-repeating-job
(partial #'song-sync-job system) frequency initial-delay)))


(comment
Expand Down

0 comments on commit 17d73f0

Please sign in to comment.