Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sid597 committed Dec 7, 2021
1 parent 60f5a5b commit 03f3dd8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 31 deletions.
8 changes: 3 additions & 5 deletions script/save-load-cronjob.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ FOLDER=/var/lib/athens/backups
# - Monotonically increasing no.
# - No. of files in folder + 1

# I am going with the 3rd option because it is the simplest one to follow.
# Using `find` instead of `ls`: https://github.com/koalaman/shellcheck/wiki/SC2012
FILENUMBER=$(find $FOLDER | wc -l)
FILENAME="backup-no-$FILENUMBER"
# Going with the Timestamp option
TIMESTAMP=$(date +%F-%H-%M)
FILENAME="${FOLDER} ${TIMESTAMP} .edn"

# command to save ledger

yarn cli:save -f "$FILENAME"
23 changes: 14 additions & 9 deletions src/clj/athens/self_hosted/components/fluree.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
[fluree.db.api :as fdb]))


(defn create-fluree-comp
[address]
;; Wrap conn in an atom so we can reconnect without restarting component.
(let [conn-atom (atom nil)
reconnect-fn (fn []
(when-some [conn @conn-atom]
(fdb/close conn))
(reset! conn-atom (fdb/connect address)))
comp {:conn-atom conn-atom
:reconnect-fn reconnect-fn}]
comp))


(defrecord Fluree
[config conn-atom reconnect-fn]

Expand All @@ -21,15 +34,7 @@
component)
(do
(log/info "Starting Fluree connection, servers" servers)
(let [;; Wrap conn in an atom so we can reconnect without restarting component.
conn-atom (atom nil)
reconnect-fn (fn []
(when-some [conn @conn-atom]
(fdb/close conn))
(reset! conn-atom (fdb/connect servers)))
comp {:conn-atom conn-atom
:reconnect-fn reconnect-fn}]
(reconnect-fn)
(let [comp (create-fluree-comp servers)]
;; Initialize event log.
(event-log/ensure-ledger! comp)
(merge component comp))))))
Expand Down
16 changes: 3 additions & 13 deletions src/clj/athens/self_hosted/event_log.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
(def ledger "events/log")


(defn create-fluree-comp
[address]
(let [conn-atom (atom nil)
reconnect-fn (fn []
(when-some [conn @conn-atom]
(fdb/close conn))
(reset! conn-atom (fdb/connect address)))
comp {:conn-atom conn-atom
:reconnect-fn reconnect-fn}]
(reconnect-fn)
comp))


(def schema
[{:_id :_collection
Expand Down Expand Up @@ -57,6 +45,8 @@
(defn deserialize
[{id "event/id"
data "event/data"}]
;; In some running ledgers we have "add Welcome page shortcut" that does not have a UUID
;; So we want the backup to be compatible for these previous version of ledgers.
[(if (str/blank? id)
(UUID/randomUUID)
(UUID/fromString id)) (edn/read-string data)])
Expand Down Expand Up @@ -217,7 +207,7 @@
((:reconnect-fn comp))

;; Create ledger if not present.
(ensure-ledger! comp )
(ensure-ledger! comp)

;; What are the current events in the ledger?
(events comp)
Expand Down
5 changes: 3 additions & 2 deletions src/clj/athens/self_hosted/save_load.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:gen-class)
(:require
[athens.self-hosted.event-log :as event-log]
[athens.self-hosted.components.fluree :as fluree-comp]
[clojure.edn :as edn]
[clojure.string :as string]
[clojure.tools.cli :refer [parse-opts]]
Expand All @@ -13,7 +14,7 @@
[args]
(let [{:keys [fluree-address
filename]} args
comp (event-log/create-fluree-comp fluree-address)
comp (fluree-comp/create-fluree-comp fluree-address)
events (event-log/events comp)]
;; Save the ledger on file
;; TODO : Who should discover the name for file to save?
Expand All @@ -26,7 +27,7 @@
[args]
(let [{:keys [fluree-address
filename]} args
comp (event-log/create-fluree-comp fluree-address)
comp (fluree-comp/create-fluree-comp fluree-address)
conn (-> comp
:conn-atom
deref)
Expand Down
3 changes: 1 addition & 2 deletions src/cljc/athens/athens_datoms.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
(let [op (bfs/build-paste-op (datascript/empty-db common-db/schema)
welcome-page-internal-representation)
welcome-page (common-events/build-atomic-event op)
;; TODO NOW this is wrong need to wrap in build-atomic-event to create a uuid
add-sidebar (atomic-graph-ops/make-shortcut-new-op welcome-page-title)]
add-sidebar (common-events/build-atomic-event (atomic-graph-ops/make-shortcut-new-op welcome-page-title))]
[[(:event/id welcome-page) welcome-page]
[(:event/id add-sidebar) add-sidebar]]))

0 comments on commit 03f3dd8

Please sign in to comment.