Skip to content

Commit

Permalink
centralised migration orchestration - directly publishing to leader p…
Browse files Browse the repository at this point in the history
…roject
  • Loading branch information
YabMas committed Jan 16, 2024
1 parent d22337d commit 6b5efa2
Showing 1 changed file with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,48 @@
{:status 500
:body "Unexpected error"})))

(def ^:private migrations-topic "dare-migrations")
; for now migration leaders are hardcoded to be in the us region
(defn ^:private project-id->migrations-topic [project-id]
(let [[app-name stage _] (-> project-id (str/split #"-"))
leader-project (str/join "-" [app-name stage "us"])]
(str "projects/" leader-project "/topics/dare-migrations")))

(defn ^:private handle-migration-event [{:keys [installation migration-data tenant-ref]}]
(let [tenant (:clientKey installation)
{:keys [phase start-time end-time]} migration-data]
(condp contains? (:phase migration-data)
#{"schedule"}
(let [source-project (get-project-id)
[app-name stage _] (->
source-project
(str/split #"-"))
destination-region-label (str/lower-case (:location migration-data))
destination-project (str/join "-" [app-name stage destination-region-label])]
(pubsub/publish-message!
migrations-topic
{:attributes
{:tenant tenant
:source_project source-project
:destination_project destination-project
:start_time start-time
:end_time end-time}}))
(let [source-project (get-project-id)
[app-name stage _] (->
source-project
(str/split #"-"))
destination-region-label (str/lower-case (:location migration-data))
destination-project (str/join "-" [app-name stage destination-region-label])]
(pubsub/publish-message!
(project-id->migrations-topic source-project)
{:attributes
{:tenant tenant
:source_project source-project
:destination_project destination-project
:start_time start-time
:end_time end-time}}))
#{"start" "commit" "rollback"}
(p/let [token (->
^js (GoogleAuth.)
(.getAccessToken))
callback-url (p/->
tenant-ref
(.get)
(.data)
->clj
:migrationCallback)]
(http/request
{::http/base-url callback-url
::http/method "POST"
::http/headers
{"Content-Type" "application/json"
"Authorization" (str "Bearer " token)}
::http/body {:phase phase}})))))
(p/let [token (->
^js (GoogleAuth.)
(.getAccessToken))
callback-url (p/->
tenant-ref
(.get)
(.data)
->clj
:migrationCallback)]
(http/request
{::http/base-url callback-url
::http/method "POST"
::http/headers
{"Content-Type" "application/json"
"Authorization" (str "Bearer " token)}
::http/body {:phase phase}})))))

(defn ^:private migration-handler
[{:keys [installation]
Expand Down

0 comments on commit 6b5efa2

Please sign in to comment.