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

Utilizando nossa lib components #311

Merged
merged 6 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,34 @@
com.fbeyer/refx {:mvn/version "0.0.49"}
lilactown/helix {:mvn/version "0.1.9"}
funcool/promesa {:mvn/version "9.0.494"}
org.clojure/core.async {:mvn/version "1.6.681"}

metosin/reitit-schema {:mvn/version "0.5.18"}
metosin/reitit-frontend {:mvn/version "0.5.18"}
lambdaisland/fetch {:mvn/version "1.1.60"}

;; back
com.moclojer/components {:git/url "https://github.com/moclojer/components.git"
:git/sha "ad3ba26b129b55d54f004e8b8d3a46f3594e4547"}
com.cognitect.aws/api {:mvn/version "0.8.561"}
com.cognitect.aws/endpoints {:mvn/version "1.1.12.230"}
com.cognitect.aws/s3 {:mvn/version "822.2.1145.0"}
aero/aero {:mvn/version "1.1.6"}
org.clojure/core.async {:mvn/version "1.6.681"}
buddy/buddy-sign {:mvn/version "3.5.351"}
cheshire/cheshire {:mvn/version "5.11.0"}
clj-http/clj-http {:mvn/version "3.12.3"}
com.fzakaria/slf4j-timbre {:mvn/version "0.3.21"}
com.github.seancorfield/honeysql {:mvn/version "2.3.928"}
com.github.seancorfield/next.jdbc {:mvn/version "1.3.834"}
com.stuartsierra/component {:mvn/version "1.1.0"}
com.taoensso/timbre {:mvn/version "6.3.1"}
viesti/timbre-json-appender {:mvn/version "0.2.13"}
com.zaxxer/HikariCP {:mvn/version "5.0.1"}
io.pedestal/pedestal.jetty {:mvn/version "0.5.10"}
io.pedestal/pedestal.service {:mvn/version "0.5.10"}
com.fzakaria/slf4j-timbre {:mvn/version "0.3.21"}
com.taoensso/timbre {:mvn/version "6.3.1"}
metosin/malli {:mvn/version "0.11.0"}
metosin/muuntaja {:mvn/version "0.6.8"}
metosin/reitit {:mvn/version "0.5.18"}
metosin/reitit-pedestal {:mvn/version "0.5.18"}
metosin/reitit-swagger {:mvn/version "0.5.18"}
metosin/reitit-swagger-ui {:mvn/version "0.5.18"}
migratus/migratus {:mvn/version "1.5.1"}
org.bouncycastle/bcprov-jdk15on {:mvn/version "1.70"}
org.postgresql/postgresql {:mvn/version "42.6.0"}
org.slf4j/slf4j-simple {:mvn/version "2.0.2"}
selmer/selmer {:mvn/version "1.12.55"}
redis.clients/jedis {:mvn/version "5.1.2"}
io.forward/yaml {:mvn/version "1.0.11"}
io.github.cljazz/supabase {:git/sha "a850ed47eb0daa8303f206ea60bd4b3bf59e1e0a"
:git/url "https://github.com/cljazz/supabase-clj"}
babashka/process {:mvn/version "0.5.22"}
io.sentry/sentry {:mvn/version "7.6.0"}
io.sentry/sentry-clj {:mvn/version "7.6.215"}}
babashka/process {:mvn/version "0.5.22"}}

:aliases
{;; frontend
Expand All @@ -69,7 +57,7 @@
:clojure-lsp {:replace-deps {com.github.clojure-lsp/clojure-lsp-standalone {:mvn/version "2022.09.01-15.27.31"}}
:main-opts ["-m" "clojure-lsp.main"]}
;; clj -M:migratus
:migratus {:main-opts ["-m" "components.migrations"]}
:migratus {:main-opts ["-m" "com.moclojer.components.migrations"]}
;; clj -X:run
:run {:main-opts ["-m" "back.api.server"]
:exec-fn back.api.server/-main}
Expand Down
6 changes: 3 additions & 3 deletions resources/back/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
:proxy-pass #or [#env PROXY_PASS "foobar"]}
:max-verification-attempts 20
:verification-timeout-ms 3000}
:redis-worker {:uri #or [#env REDIS_URL "redis://localhost:6379"]}
:redis-publisher {:uri #or [#env REDIS_URL "redis://localhost:6379"]}
:mq {:uri #or [#env REDIS_URL "redis://localhost:6379"]}
:database {:dbtype "postgres"
:jdbc-url #or [#env DATABASE_URL "postgresql://localhost:5432/postgres?user=postgres&password=postgres"]}}
:jdbc-url #or [#env DATABASE_URL "postgresql://localhost:5432/postgres?user=postgres&password=postgres"]}
:migration-dir "back/migrations"}

2 changes: 1 addition & 1 deletion src/back/api/controllers/mocks.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[back.api.db.mocks :as db.mocks]
[back.api.logic.mocks :as logic.mocks]
[back.api.ports.producers :as ports.producers]
[components.logs :as logs]))
[com.moclojer.components.logs :as logs]))

(defn create-mock!
[user-id mock {:keys [database publisher]}]
Expand Down
7 changes: 3 additions & 4 deletions src/back/api/db/customers.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns back.api.db.customers
(:require
[components.database :as database]
[honey.sql :as sql]
[honey.sql.helpers :as sql.helpers]))
(:require [com.moclojer.components.database :as database]
[honey.sql :as sql]
[honey.sql.helpers :as sql.helpers]))

(defn insert!
[transaction db]
Expand Down
2 changes: 1 addition & 1 deletion src/back/api/db/mocks.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns back.api.db.mocks
(:require [components.database :as database]
(:require [com.moclojer.components.database :as database]
[honey.sql :as sql]
[honey.sql.helpers :as sql.helpers]))

Expand Down
3 changes: 1 addition & 2 deletions src/back/api/healthcheck.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns back.api.healthcheck
(:require
[components.database :as database]))
(:require [com.moclojer.components.database :as database]))

(def Content
[:map
Expand Down
18 changes: 9 additions & 9 deletions src/back/api/ports/producers.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
(ns back.api.ports.producers
(:require [components.redis-publisher :as redis-publisher]))
(:require [com.moclojer.components.publisher :as publisher]))

(defn publish-mock-event [mock queue-name publisher]
(redis-publisher/publish! publisher queue-name {:event mock}))
(publisher/publish! publisher queue-name {:event mock}))

(defn publish-mock-changed-event [mock-id publisher]
(redis-publisher/publish! publisher "mock.changed" {:event {:mock-id mock-id}}))
(publisher/publish! publisher "mock.changed" {:event {:mock-id mock-id}}))

(defn verify-domain!
[domain retrying? skip-data? publisher]
(redis-publisher/publish! publisher "domain.verify"
{:event {:domain domain
:retrying? retrying?
:skip-data? skip-data?}}))
(publisher/publish! publisher "domain.verify"
{:event {:domain domain
:retrying? retrying?
:skip-data? skip-data?}}))

(defn verify-unified!
[mocks publisher]
(redis-publisher/publish! publisher "unified.verify"
{:event {:mocks mocks}}))
(publisher/publish! publisher "unified.verify"
{:event {:mocks mocks}}))
35 changes: 14 additions & 21 deletions src/back/api/server.clj
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
(ns back.api.server
(:require [back.api.ports.workers :as p.workers]
[back.api.routes :as routes]
[com.stuartsierra.component :as component]
[components.config :as config]
[components.database :as database]
[components.http :as http]
[components.logs :as logs]
[components.migrations :as migrations]
[components.redis-publisher :as redis-publisher]
[components.redis-queue :as redis-queue]
[components.router :as router]
[components.sentry :as sentry]
[components.webserver :as webserver])
[com.moclojer.components.core :as components]
[com.moclojer.components.logs :as logs]
[com.moclojer.components.migrations :as migrations]
[com.stuartsierra.component :as component])
(:gen-class))

(def system-atom (atom nil))

(defn build-system-map []
(component/system-map
:config (config/new-config)
:http (http/new-http)
:sentry (component/using (sentry/new-sentry) [:config])
:router (router/new-router routes/routes)
:database (component/using (database/new-database) [:config])
:publisher (component/using (redis-publisher/new-redis-publisher
:config (components/new-config "back/config.edn")
:http (components/new-http)
:sentry (component/using (components/new-sentry) [:config])
:router (components/new-router routes/routes)
:database (component/using (components/new-database) [:config])
:publisher (component/using (components/new-publisher
[{:qname "domains.verification.dispatch"
:event {}
;; every 2 minutes
Expand All @@ -33,15 +26,15 @@
;; every 5 minutes
:delay 300000}])
[:config :sentry])
:webserver (component/using (webserver/new-webserver)
:webserver (component/using (components/new-webserver)
[:config :http :router :database :publisher :sentry])
:workers (component/using
(redis-queue/new-redis-queue p.workers/workers false)
(components/new-consumer p.workers/workers false)
[:config :database :publisher :sentry])))

(defn start-system! [system-map]
(logs/setup [["*" :info]] :auto :prod)
(migrations/migrate (migrations/configuration-with-db))
(components/setup-logger [["*" :info]] :auto :prod)
(migrations/migrate (migrations/build-complete-db-config "back/config.edn"))
(->> system-map
component/start
(reset! system-atom)))
Expand Down
3 changes: 2 additions & 1 deletion src/cloud_ops/api/controllers/cloud.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[cloud-ops.api.logic.cloud :as logic.cloud]
[cloud-ops.api.ports.http-out :as http-out]
[cloud-ops.api.ports.producers :as producers]
[components.logs :as logs]))
[com.moclojer.components.logs :as logs]))

(defn get-current-data
"Retrieves current data from both CloudFlare and DigitalOcean.
The naming is agnostic to records and entire specs."
Expand Down
16 changes: 8 additions & 8 deletions src/cloud_ops/api/ports/http_out.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cloud-ops.api.ports.http-out
(:require [components.http :as hp]
[components.logs :as logs]
(:require [com.moclojer.components.http :as http]
[com.moclojer.components.logs :as logs]
[muuntaja.core :as m]))

;; Since most of the requests here are a critical point of failure,
Expand All @@ -12,8 +12,8 @@
[domain http]
(try
(let [url (str "https://" domain ".moclojer.com")
resp (hp/request http {:method :get
:url url})]
resp (http/request http {:method :get
:url url})]
(:status resp))
(catch Exception e
(logs/log :warn "verifying domain"
Expand All @@ -32,7 +32,7 @@
"Retrieves the current domain records in CloudFlare."
[http req-params]
(let [req (assoc req-params :method :get)
{:keys [body]} (hp/request-or-throw http req 200)
{:keys [body]} (http/request-or-throw http req 200)
{:keys [result]} (m/decode "application/json" body)]
(logs/log :info "retrieved cloudflare records")
result))
Expand All @@ -48,7 +48,7 @@
:ttl 1})
req (merge req-params {:method :post
:body enc-body})
{:keys [body]} (hp/request-or-throw http req 200)
{:keys [body]} (http/request-or-throw http req 200)
decoded (m/decode "application/json" body)]
(logs/log :info "created cloudflare domain"
:ctx {:domain domain})
Expand All @@ -60,7 +60,7 @@
the app. We actually don't need all of that, so we clean it afterwards."
[http req-params]
(let [req (assoc req-params :method :get)
{:keys [body]} (hp/request-or-throw http req 200)
{:keys [body]} (http/request-or-throw http req 200)
decoded (m/decode "application/json" body)]
(logs/log :info "retrieved digital ocean spec")
(get-in decoded [:app :spec])))
Expand All @@ -76,7 +76,7 @@
(let [enc-spec (m/encode "application/json" {:spec new-spec})
req (merge req-params {:method :put
:body enc-spec})
{:keys [body]} (hp/request-or-throw http req 200)
{:keys [body]} (http/request-or-throw http req 200)
decoded (m/decode "application/json" body)]
(logs/log :info "updated digital ocean spec")
decoded))
22 changes: 11 additions & 11 deletions src/cloud_ops/api/ports/producers.clj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(ns cloud-ops.api.ports.producers
(:require [components.redis-publisher :as redis-publisher]))
(:require [com.moclojer.components.publisher :as publisher]))

(defn create-domain!
[domain retrying? publisher]
(redis-publisher/publish! publisher "domain.create"
{:event {:domain domain
:retrying? retrying?}}))
(publisher/publish! publisher "domain.create"
{:event {:domain domain
:retrying? retrying?}}))

(defn verify-domain!
[domain retrying? skip-data? publisher]
(redis-publisher/publish! publisher "domain.verify"
{:event {:domain domain
:retrying? retrying?
:skip-data? skip-data?}}))
(publisher/publish! publisher "domain.verify"
{:event {:domain domain
:retrying? retrying?
:skip-data? skip-data?}}))

(defn set-publication-status!
[domain new-status publisher]
(redis-publisher/publish! publisher "mock.publication"
{:event {:domain domain
:new-status new-status}}))
(publisher/publish! publisher "mock.publication"
{:event {:domain domain
:new-status new-status}}))
2 changes: 1 addition & 1 deletion src/cloud_ops/api/ports/workers.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cloud-ops.api.ports.workers
(:require [cloud-ops.api.controllers.cloud :as controllers.cloud]
[components.logs :as logs]))
[com.moclojer.components.logs :as logs]))

(defn create-domain-handler
[{:keys [event]} components]
Expand Down
29 changes: 13 additions & 16 deletions src/cloud_ops/api/server.clj
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
(ns cloud-ops.api.server
(:require [cloud-ops.api.ports.workers :as p.workers]
[com.moclojer.components.core :as components]
[com.moclojer.components.logs :as logs]
[com.stuartsierra.component :as component]
[components.config :as config]
[components.http :as http]
[components.logs :as logs]
[components.redis-publisher :as redis-publisher]
[components.redis-queue :as redis-queue]
[components.sentry :as sentry])
[components.publisher :as publisher])
(:gen-class))

(def system-atom (atom nil))

(defn build-system-map []
(component/system-map
:config (config/new-config)
:http (http/new-http)
:sentry (component/using (sentry/new-sentry) [:config])
;; :sentry (sentry/new-mock-sentry)
:config (components/new-config "back/config.edn")
:http (components/new-http)
:sentry (component/using (components/new-sentry) [:config])
;; :sentry (components/new-sentry-mock)
:publisher (component/using
(redis-publisher/new-redis-publisher)
(components/new-publisher)
[:config :sentry])
:workers (component/using
(redis-queue/new-redis-queue p.workers/workers true)
(components/new-consumer p.workers/workers true)
[:config :http :publisher :sentry])))

(defn start-system! [system-map]
(logs/setup [["*" :info]] :auto :prod)
(components/setup-logger [["*" :info]] :auto :prod)
(->> system-map
component/start
(reset! system-atom)))
Expand All @@ -47,9 +44,9 @@
(comment
(start-system! (build-system-map))

(redis-publisher/publish! (:publisher @system-atom) "domain.create"
{:event {:domain "nao-existe-123-j0suetm"
:retrying? false}})
(publisher/publish! (:publisher @system-atom) "domain.create"
{:event {:domain "nao-existe-123-j0suetm"
:retrying? false}})

(stop-system!)
;;
Expand Down
18 changes: 0 additions & 18 deletions src/components/README.md

This file was deleted.

Loading
Loading