better health check.

This commit is contained in:
Bryce Covert
2020-09-17 07:05:23 -07:00
parent 80efc14d3a
commit 2e18e2da26
11 changed files with 88 additions and 190 deletions

View File

@@ -1,9 +0,0 @@
(ns auto-ap.routes.checks
(:require
[hiccup.core :refer [html]]
[auto-ap.routes.utils :refer [wrap-secure]]
[compojure.core :refer [GET POST context defroutes wrap-routes]]))
(defroutes routes
(wrap-routes
(context "/checks" [])
wrap-secure))

View File

@@ -1,29 +0,0 @@
(ns auto-ap.routes.clients
(:require [auto-ap.datomic.clients :as clients]
[auto-ap.graphql.utils :refer [can-see-client? assert-can-see-client]]
[auto-ap.routes.utils :refer [wrap-secure wrap-spec]]
[auto-ap.entities.clients :as entity]
[compojure.core :refer [GET PUT context defroutes
wrap-routes]]))
(defroutes routes
(wrap-routes
(context "/clients" []
#_(wrap-spec
(PUT "/:id" {{:keys [address email locations new-bank-accounts]} :edn-params :keys [edn-params] {:keys [id ]} :route-params :as r}
(assert-can-see-client (:identity r) id)
(let [id (Integer/parseInt id)
company (d-clients/get-by-id id)
updated-company (merge company {:address address
:email email
:locations locations})]
#_(companies/upsert id updated-company)
#_(doseq [bank-account new-bank-accounts]
(companies/add-bank-account id bank-account))
{:status 200
:body (pr-str (clients/get-by-id id))
:headers {"Content-Type" "application/edn"}}))
::entity/company))
wrap-secure))

View File

@@ -1,100 +0,0 @@
(ns auto-ap.routes.reminders
(:require
[auto-ap.routes.utils :refer [wrap-secure]]
[auto-ap.graphql.utils :refer [assert-admin]]
[config.core :refer [env]]
[clj-http.client :as http]
[clj-time.coerce :as c]
[clj-time.core :as time]
[clj-time.periodic :as p]
[clj-time.predicates :as pred]
[clojure.data.json :as json]
[compojure.core :refer [GET PUT POST context defroutes
wrap-routes]])
(:import (org.joda.time DateTime)))
#_(POST "/:id/remind" {:keys [edn-params] {:keys [id :<< as-int]} :route-params :as r}
(assert-admin (:identity r))
(let [id (if (int? id)
id
(Integer/parseInt id))
vendor (vendors/get-by-id id)]
(reminders/insert (assoc
(reminders/template)
:email (:primary-email vendor)
:vendor-id id
:scheduled (time/now)))
(-> (reminders/get-ready)
(reminders/send-emails))
{:status 200
:body "{}"
:headers {"Content-Type" "application/edn"}}))
#_(defn next-sunday []
(let [sunday (->> (p/periodic-seq (time/plus (time/today) (time/days 1)) (time/days 1))
(filter pred/sunday?)
first)]
(time/from-time-zone (time/date-time (time/year sunday) (time/month sunday) (time/day sunday))
(time/time-zone-for-id "America/Los_Angeles"))))
#_(defn schedule-reminders []
(let [vendors (vendors/find-with-reminders)
future-reminders (reminders/find-future (map :id vendors))
has-reminder-scheduled? (set (map :vendor-id future-reminders))
vendors-without-scheduled (filter #(not (has-reminder-scheduled? (:id %))) vendors)]
(println "Reminders already scheduled:" future-reminders)
(println "Reminders will happen at" (next-sunday))
(println "Reminders to schedule" vendors-without-scheduled)
(doseq [{:keys [id primary-email invoice-reminder-schedule]} vendors-without-scheduled]
(reminders/insert (assoc (reminders/template)
:vendor-id id
:email primary-email
:scheduled (next-sunday))))))
#_(defn find-ready-reminders []
(let [vendors (vendors/get-all)
ready-reminders (reminders/get-ready)]
ready-reminders))
#_(defn replace-joda [x]
(into {} (map (fn [[k v]]
[k (if (instance? DateTime v)
(c/to-date v)
v)])
x)))
(defroutes routes
(context "/reminders" []
#_(POST "/send" {:keys [query-params headers body] :as x}
(let [notification-type (get headers "x-amz-sns-message-type")]
(println "Received notification " notification-type)
(if (= "SubscriptionConfirmation" notification-type)
(do
(println "Responding to confirmation" )
(let [json (json/read-str (slurp body))]
(println json)
(http/get (get json "SubscribeURL"))))
(do
(println "Scheduling")
(schedule-reminders)
(-> (reminders/get-ready)
(reminders/send-emails)))))
{:status 200
:body "{}"
:headers {"Content-Type" "application/edn"}})
#_(wrap-routes
(PUT "/:id" {:keys [ edn-params] {:keys [id] } :route-params identity :identity}
(assert-admin identity)
(let [id (if (int? id)
id
(Integer/parseInt id))]
(assert (not (:sent (reminders/get-by-id id))))
(reminders/update! id edn-params)
{:status 200
:body "{}"
:headers {"Content-Type" "application/edn"}}))
wrap-secure)))