Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

centralised migration orchestration - directly publishing to leader project #56

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,27 @@
{: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 environment _] (->
project-id
(str/split #"-"))
leader-project (str/join "-" [app-name environment "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 #"-"))
[app-name environment _] (->
source-project
(str/split #"-"))
destination-region-label (str/lower-case (:location migration-data))
destination-project (str/join "-" [app-name stage destination-region-label])]
destination-project (str/join "-" [app-name environment destination-region-label])]
(pubsub/publish-message!
migrations-topic
(project-id->migrations-topic source-project)
{:attributes
{:tenant tenant
:source_project source-project
Expand Down