From 8774a3951c735343659d702a15f483312dc9a72a Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 30 Sep 2022 08:34:13 -0700 Subject: [PATCH] adds yodlee2 accounts --- src/clj/auto_ap/graphql.clj | 3 ++- src/clj/auto_ap/jobs/yodlee2.clj | 3 +++ src/clj/auto_ap/server.clj | 3 +++ .../views/pages/admin/import_batches.cljs | 20 +++++++++++++++++-- terraform/background-job/main.tf | 7 +++++-- terraform/deploy.tf | 12 +++++++++++ 6 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 1d3f2fa9..fd6f8b5a 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -536,7 +536,8 @@ :mutations {:request_import {:type 'String - :args {:which {:type 'String}} + :args {:which {:type 'String} + :args {:type 'String}} :resolve :mutation/request-import} :delete_transaction_rule diff --git a/src/clj/auto_ap/jobs/yodlee2.clj b/src/clj/auto_ap/jobs/yodlee2.clj index fa3de94a..aec0e65b 100644 --- a/src/clj/auto_ap/jobs/yodlee2.clj +++ b/src/clj/auto_ap/jobs/yodlee2.clj @@ -5,6 +5,9 @@ [auto-ap.jobs.core :refer [execute]] [auto-ap.yodlee.core2 :as client2])) +(defn accounts-only [] + (execute "yodlee2-accounts" client2/upsert-accounts)) + (defn -main [& _] (execute "import-yodlee" (fn [] (client2/upsert-accounts) diff --git a/src/clj/auto_ap/server.clj b/src/clj/auto_ap/server.clj index 3cf5e078..3513c431 100644 --- a/src/clj/auto_ap/server.clj +++ b/src/clj/auto_ap/server.clj @@ -100,6 +100,9 @@ (= job "yodlee2") (job-yodlee2/-main) + (= job "yodlee2_accounts") + (job-yodlee2/accounts-only) + (= job "plaid") (job-plaid/-main) diff --git a/src/cljs/auto_ap/views/pages/admin/import_batches.cljs b/src/cljs/auto_ap/views/pages/admin/import_batches.cljs index 53ecd15c..0032d977 100644 --- a/src/cljs/auto_ap/views/pages/admin/import_batches.cljs +++ b/src/cljs/auto_ap/views/pages/admin/import_batches.cljs @@ -85,6 +85,15 @@ :query "mutation RequestIntuitImport{request_import(which: \":plaid\")}" :on-success [::success-plaid]}})) +(re-frame/reg-event-fx + ::request-yodlee2-accounts + [with-user ] + (fn [{:keys [user]} [_ _]] + {:graphql {:token user + :owns-state {:single ::yodlee2-accounts} + :query "mutation RequestIntuitImport{request_import(which: \":yodlee2-accounts\")}" + :on-success [::success-yodlee2-accounts]}})) + (re-frame/reg-event-fx ::mounted @@ -108,6 +117,7 @@ (let [user @(re-frame/subscribe [::subs/user]) intuit-request-import-status @(re-frame/subscribe [::status/single ::intuit]) yodlee2-request-import-status @(re-frame/subscribe [::status/single ::yodlee2]) + yodlee2-accounts-request-import-status @(re-frame/subscribe [::status/single ::yodlee2-accounts]) plaid-request-import-status @(re-frame/subscribe [::status/single ::plaid]) message @(re-frame/subscribe [::msg])] [:div @@ -136,8 +146,14 @@ :on-click (dispatch-event [::request-plaid]) :disabled (status/disabled-for plaid-request-import-status) :class (status/class-for plaid-request-import-status)} - "Start Plaid Import"]]] - [table/table {:id :import-batches + "Start Plaid Import"] + [:button.button.is-primary-two {:aria-haspopup true + :type "button" + :on-click (dispatch-event [::request-yodlee2-accounts]) + :disabled (status/disabled-for yodlee2-accounts-request-import-status) + :class (status/class-for yodlee2-accounts-request-import-status)} + "Start Yodlee Accounts"]]] + [table/table {:id :import-batches :data-page ::page}]])])) {:component-did-mount (dispatch-event [::mounted ]) :component-will-unmount #(re-frame/dispatch-sync [::unmounted])})) diff --git a/terraform/background-job/main.tf b/terraform/background-job/main.tf index 0d36ccd3..d7455c24 100644 --- a/terraform/background-job/main.tf +++ b/terraform/background-job/main.tf @@ -3,7 +3,8 @@ variable "task_role_arn" {} variable "execution_role_arn" {} variable "stage" {} variable "job_name" {} -variable "schedule" {} +variable "schedule" { default = "rate(1 hour)" } +variable "use_schedule" { default = true } variable "cpu" { default = 2048 } variable "memory" { default = 8192 } @@ -22,6 +23,7 @@ resource "aws_ecs_task_definition" "background_taskdef" { } resource "aws_cloudwatch_event_rule" "schedule" { + count = var.use_schedule ? 1 : 0 name = "${var.job_name}-schedule" schedule_expression = "${var.schedule}" } @@ -29,9 +31,10 @@ resource "aws_cloudwatch_event_rule" "schedule" { resource "aws_cloudwatch_event_target" "job_target" { + count = var.use_schedule ? 1 : 0 target_id = "${var.job_name}" arn = var.ecs_cluster - rule = aws_cloudwatch_event_rule.schedule.name + rule = aws_cloudwatch_event_rule.schedule[0].name role_arn = "arn:aws:iam::679918342773:role/service-role/Amazon_EventBridge_Invoke_ECS_1758992733" ecs_target { diff --git a/terraform/deploy.tf b/terraform/deploy.tf index 621aa828..ed55a9fa 100644 --- a/terraform/deploy.tf +++ b/terraform/deploy.tf @@ -405,4 +405,16 @@ module "close_auto_invoices_job" { execution_role_arn = var.execution_role_arn memory = 2048 cpu = 512 +} + +module "yodlee2_accounts_job" { + source = "./background-job/" + ecs_cluster = var.ecs_cluster + task_role_arn = var.task_role_arn + stage = var.stage + job_name = "yodlee2-accounts" + execution_role_arn = var.execution_role_arn + use_schedule = false + memory = 1024 + cpu = 512 } \ No newline at end of file