From d463c61fa2d6dd7b7ee4d1f1d6bcdbe3a1a8def2 Mon Sep 17 00:00:00 2001 From: "pedro_.fp" Date: Fri, 13 Jan 2023 15:54:08 +0000 Subject: [PATCH 01/21] Notify ninjas on their birthday --- lib/bokken/accounts.ex | 6 +++++ lib/bokken/application.ex | 4 ++- lib/bokken/periodically.ex | 24 +++++++++++++++++ .../controllers/ninja_controller.ex | 27 +++++++++++++++++++ lib/bokken_web/emails/event_emails.ex | 8 ++++++ lib/bokken_web/router.ex | 2 ++ .../templates/email/ninja_birthday.html.eex | 0 .../templates/email/ninja_birthday.text.eex | 0 8 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 lib/bokken/periodically.ex create mode 100644 lib/bokken_web/templates/email/ninja_birthday.html.eex create mode 100644 lib/bokken_web/templates/email/ninja_birthday.text.eex diff --git a/lib/bokken/accounts.ex b/lib/bokken/accounts.ex index 0e0c55d8..37ac520a 100644 --- a/lib/bokken/accounts.ex +++ b/lib/bokken/accounts.ex @@ -258,6 +258,12 @@ defmodule Bokken.Accounts do |> Repo.all() end + def list_ninjas_preload(args) do + Ninja + |> Repo.all() + |> Repo.preload(args) + end + @doc """ Gets a single ninja. diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index ede80ace..820bca5b 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -15,9 +15,11 @@ defmodule Bokken.Application do # Start the PubSub system {Phoenix.PubSub, name: Bokken.PubSub}, # Start the Endpoint (http/https) - BokkenWeb.Endpoint + BokkenWeb.Endpoint, # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} + Bokken.Periodically + # Executes an endpoint periodically ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex new file mode 100644 index 00000000..d07a3bce --- /dev/null +++ b/lib/bokken/periodically.ex @@ -0,0 +1,24 @@ +defmodule Bokken.Periodically do + use GenServer + + alias BokkenWeb.NinjaController + + def start_link(_opts) do + GenServer.start_link(__MODULE__, %{}) + end + + def init(state) do + schedule_work() + {:ok, state} + end + + def handle_info(:work, state) do + NinjaController.notify_ninja_birthday() + schedule_work() + {:noreply, state} + end + + defp schedule_work() do + Process.send_after(self(), :work, 24 * 60 * 60 * 1000) + end +end diff --git a/lib/bokken_web/controllers/ninja_controller.ex b/lib/bokken_web/controllers/ninja_controller.ex index e53a6b82..b1cb987e 100644 --- a/lib/bokken_web/controllers/ninja_controller.ex +++ b/lib/bokken_web/controllers/ninja_controller.ex @@ -3,9 +3,11 @@ defmodule BokkenWeb.NinjaController do alias Bokken.Accounts alias Bokken.Accounts.Ninja + alias BokkenWeb.EventsEmails alias Bokken.Events.Event alias Bokken.Events.Lecture alias Bokken.Events.TeamNinja + alias Bokken.Mailer action_fallback BokkenWeb.FallbackController @@ -85,4 +87,29 @@ defmodule BokkenWeb.NinjaController do send_resp(conn, :no_content, "") end end + + def notify_ninja_birthday() do + ninjas = Accounts.list_ninjas_preload([:user]) + current_time = DateTime.utc_now() + ninjas + |> Enum.map(fn ninja -> (ninja.birthday == current_time) + send_email(ninja, EventsEmails.ninja_birthday_email(to: ninja.user.email)) + end) + end + + defp send_email(users, email) do + [users] + |> List.foldl( + %{success: [], fail: []}, + fn user, accumulator -> + case Mailer.deliver(email.(user)) do + {:ok, _} -> + %{success: [user.email | accumulator[:success]], fail: accumulator[:fail]} + + {:error, _} -> + %{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]} + end + end + ) + end end diff --git a/lib/bokken_web/emails/event_emails.ex b/lib/bokken_web/emails/event_emails.ex index 5e082bad..6656c64e 100644 --- a/lib/bokken_web/emails/event_emails.ex +++ b/lib/bokken_web/emails/event_emails.ex @@ -54,6 +54,14 @@ defmodule BokkenWeb.EventsEmails do |> render_body(:mentor_event_reminder) end + def ninja_birthday_email(to: email) do + frontend_url = Application.fetch_env!(:bokken, BokkenWeb.Endpoint)[:frontend_url] + + base_email(to: email) + |> subject("[CoderDojo Braga] O Dojo deseja-te parabéns!") + |> render_body(:ninja_birthday) + end + defp base_email(to: email) do new() |> from({"CoderDojo Braga", "noreply@coderdojobraga.org"}) diff --git a/lib/bokken_web/router.ex b/lib/bokken_web/router.ex index 05b06da2..83fd52c5 100644 --- a/lib/bokken_web/router.ex +++ b/lib/bokken_web/router.ex @@ -100,6 +100,8 @@ defmodule BokkenWeb.Router do post "/notify_signup", EventController, :notify_signup post "/notify_selected", EventController, :notify_selected + post "/notify_ninja_birthday", NinjaController, :notify_ninja_birthday + resources "/bot", BotController, except: [:new, :edit] end diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex new file mode 100644 index 00000000..e69de29b diff --git a/lib/bokken_web/templates/email/ninja_birthday.text.eex b/lib/bokken_web/templates/email/ninja_birthday.text.eex new file mode 100644 index 00000000..e69de29b From 9ec76c8228fe3c45b114b81467112dbac84749af Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 20 Jan 2023 19:52:54 +0000 Subject: [PATCH 02/21] Reformulate functions --- lib/bokken/accounts.ex | 25 ++++++---- lib/bokken/application.ex | 2 +- lib/bokken/events/event_admin.ex | 17 +++++++ lib/bokken/periodically.ex | 21 ++++++-- .../controllers/event_controller.ex | 18 +------ .../controllers/ninja_controller.ex | 26 ---------- lib/bokken_web/emails/event_emails.ex | 2 +- lib/bokken_web/router.ex | 2 +- .../templates/email/ninja_birthday.html.eex | 48 +++++++++++++++++++ .../templates/email/ninja_birthday.text.eex | 5 ++ 10 files changed, 108 insertions(+), 58 deletions(-) diff --git a/lib/bokken/accounts.ex b/lib/bokken/accounts.ex index 37ac520a..41609bdc 100644 --- a/lib/bokken/accounts.ex +++ b/lib/bokken/accounts.ex @@ -232,8 +232,11 @@ defmodule Bokken.Accounts do """ - @spec list_ninjas(map()) :: list(Ninja.t()) - def list_ninjas(args \\ %{}) + def list_ninjas(preloads) when is_list(preloads) do + Ninja + |> Repo.all() + |> Repo.preload(preloads) + end def list_ninjas(%{"team_id" => team_id}) do team_id @@ -253,15 +256,9 @@ defmodule Bokken.Accounts do |> Map.fetch!(:ninjas) end - def list_ninjas(_args) do - Ninja - |> Repo.all() - end - - def list_ninjas_preload(args) do + def list_ninjas do Ninja |> Repo.all() - |> Repo.preload(args) end @doc """ @@ -386,6 +383,16 @@ defmodule Bokken.Accounts do end end + def get_guardian_email_by_ninja(ninja: user) do + user = + user + |> Repo.preload(:ninja) + + guardian = get_guardian!(user.ninja.guardian_id, [:user]) + + guardian.user.email + end + alias Bokken.Accounts.Organizer @doc """ diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index 820bca5b..5490be18 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -19,7 +19,7 @@ defmodule Bokken.Application do # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} Bokken.Periodically - # Executes an endpoint periodically + # Executes a task periodically ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/bokken/events/event_admin.ex b/lib/bokken/events/event_admin.ex index c6d138fa..88600fcb 100644 --- a/lib/bokken/events/event_admin.ex +++ b/lib/bokken/events/event_admin.ex @@ -3,6 +3,7 @@ defmodule Bokken.Events.EventAdmin do The admin view config of events """ alias Bokken.{Events, Pairings} + alias Bokken.Mailer def list_actions(_conn) do [ @@ -46,4 +47,20 @@ defmodule Bokken.Events.EventAdmin do enrollments_close: nil ] end + + def send_email(users, email) do + users + |> List.foldl( + %{success: [], fail: []}, + fn user, accumulator -> + case Mailer.deliver(email.(user)) do + {:ok, _} -> + %{success: [user.email | accumulator[:success]], fail: accumulator[:fail]} + + {:error, _} -> + %{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]} + end + end + ) + end end diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex index d07a3bce..b3416c13 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/periodically.ex @@ -1,7 +1,11 @@ defmodule Bokken.Periodically do use GenServer - alias BokkenWeb.NinjaController + alias Bokken.Accounts + alias BokkenWeb.EventsEmails + import Bokken.Events.EventAdmin + + @one_day (24 * 60 * 60 * 1000) def start_link(_opts) do GenServer.start_link(__MODULE__, %{}) @@ -13,12 +17,23 @@ defmodule Bokken.Periodically do end def handle_info(:work, state) do - NinjaController.notify_ninja_birthday() + notify_ninja_birthday() schedule_work() {:noreply, state} end defp schedule_work() do - Process.send_after(self(), :work, 24 * 60 * 60 * 1000) + Process.send_after(self(), :work, 10000) + end + + defp notify_ninja_birthday() do + ninjas = Accounts.list_ninjas([:user]) + current_time = ~D[2008-11-25] + + ninjas + |> Enum.filter(fn ninja -> (ninja.birthday.month == current_time.month) && (ninja.birthday.day == current_time.day) && not is_nil(ninja.user) end) + |> Enum.map(fn ninja -> ninja.user end) + # |> Enum.filter(fn ninja -> (Date.compare(ninja.birthday, current_time) == :eq) end) + |> send_email(fn user -> EventsEmails.ninja_birthday_email(user.ninja, to: Accounts.get_guardian_email_by_ninja(ninja: user)) end) end end diff --git a/lib/bokken_web/controllers/event_controller.ex b/lib/bokken_web/controllers/event_controller.ex index 7c7bb74b..da31e69c 100644 --- a/lib/bokken_web/controllers/event_controller.ex +++ b/lib/bokken_web/controllers/event_controller.ex @@ -4,8 +4,8 @@ defmodule BokkenWeb.EventController do alias Bokken.Accounts alias Bokken.Events alias Bokken.Events.Event - alias Bokken.Mailer alias BokkenWeb.EventsEmails + import Bokken.Events.EventAdmin action_fallback BokkenWeb.FallbackController @@ -143,20 +143,4 @@ defmodule BokkenWeb.EventController do |> render("emails.json", res) end end - - defp send_email(users, email) do - users - |> List.foldl( - %{success: [], fail: []}, - fn user, accumulator -> - case Mailer.deliver(email.(user)) do - {:ok, _} -> - %{success: [user.email | accumulator[:success]], fail: accumulator[:fail]} - - {:error, _} -> - %{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]} - end - end - ) - end end diff --git a/lib/bokken_web/controllers/ninja_controller.ex b/lib/bokken_web/controllers/ninja_controller.ex index b1cb987e..e44ca086 100644 --- a/lib/bokken_web/controllers/ninja_controller.ex +++ b/lib/bokken_web/controllers/ninja_controller.ex @@ -3,11 +3,9 @@ defmodule BokkenWeb.NinjaController do alias Bokken.Accounts alias Bokken.Accounts.Ninja - alias BokkenWeb.EventsEmails alias Bokken.Events.Event alias Bokken.Events.Lecture alias Bokken.Events.TeamNinja - alias Bokken.Mailer action_fallback BokkenWeb.FallbackController @@ -88,28 +86,4 @@ defmodule BokkenWeb.NinjaController do end end - def notify_ninja_birthday() do - ninjas = Accounts.list_ninjas_preload([:user]) - current_time = DateTime.utc_now() - ninjas - |> Enum.map(fn ninja -> (ninja.birthday == current_time) - send_email(ninja, EventsEmails.ninja_birthday_email(to: ninja.user.email)) - end) - end - - defp send_email(users, email) do - [users] - |> List.foldl( - %{success: [], fail: []}, - fn user, accumulator -> - case Mailer.deliver(email.(user)) do - {:ok, _} -> - %{success: [user.email | accumulator[:success]], fail: accumulator[:fail]} - - {:error, _} -> - %{success: [accumulator[:success]], fail: [user.email | accumulator[:fail]]} - end - end - ) - end end diff --git a/lib/bokken_web/emails/event_emails.ex b/lib/bokken_web/emails/event_emails.ex index 6656c64e..dfccb9bf 100644 --- a/lib/bokken_web/emails/event_emails.ex +++ b/lib/bokken_web/emails/event_emails.ex @@ -54,7 +54,7 @@ defmodule BokkenWeb.EventsEmails do |> render_body(:mentor_event_reminder) end - def ninja_birthday_email(to: email) do + def ninja_birthday_email(ninja, to: email) do frontend_url = Application.fetch_env!(:bokken, BokkenWeb.Endpoint)[:frontend_url] base_email(to: email) diff --git a/lib/bokken_web/router.ex b/lib/bokken_web/router.ex index 83fd52c5..4b888430 100644 --- a/lib/bokken_web/router.ex +++ b/lib/bokken_web/router.ex @@ -100,7 +100,7 @@ defmodule BokkenWeb.Router do post "/notify_signup", EventController, :notify_signup post "/notify_selected", EventController, :notify_selected - post "/notify_ninja_birthday", NinjaController, :notify_ninja_birthday + # post "/notify_ninja_birthday", NinjaController, :notify_ninja_birthday resources "/bot", BotController, except: [:new, :edit] end diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex index e69de29b..9e0355c0 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.html.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.html.eex @@ -0,0 +1,48 @@ + + + + + + + diff --git a/lib/bokken_web/templates/email/ninja_birthday.text.eex b/lib/bokken_web/templates/email/ninja_birthday.text.eex index e69de29b..8ce720eb 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.text.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.text.eex @@ -0,0 +1,5 @@ +Olá 👋 + +Infelizmente, informamos que o(a) ninjanão foi selecionado(a) para participar na próxima sessão. + +Agradecemos o interesse em participar no Coderdojo Braga. Tentaremos que o seu/ a sua ninja possa participar em sessões futuras. \ No newline at end of file From cc81943eb0ff98db96499935f3d7762ec58048be Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 20 Jan 2023 23:22:38 +0000 Subject: [PATCH 03/21] Adjusted notify_ninja_birthday --- lib/bokken/periodically.ex | 18 +++++++++----- .../controllers/ninja_controller.ex | 1 - lib/bokken_web/emails/event_emails.ex | 3 +-- lib/bokken_web/router.ex | 2 -- .../templates/email/ninja_birthday.html.eex | 24 +++++++++++++++++++ .../templates/email/ninja_birthday.text.eex | 6 ++--- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex index b3416c13..a9920bba 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/periodically.ex @@ -5,7 +5,7 @@ defmodule Bokken.Periodically do alias BokkenWeb.EventsEmails import Bokken.Events.EventAdmin - @one_day (24 * 60 * 60 * 1000) + @one_day 24 * 60 * 60 * 1000 def start_link(_opts) do GenServer.start_link(__MODULE__, %{}) @@ -23,17 +23,23 @@ defmodule Bokken.Periodically do end defp schedule_work() do - Process.send_after(self(), :work, 10000) + Process.send_after(self(), :work, @one_day) end defp notify_ninja_birthday() do ninjas = Accounts.list_ninjas([:user]) - current_time = ~D[2008-11-25] + current_time = Date.utc_today() ninjas - |> Enum.filter(fn ninja -> (ninja.birthday.month == current_time.month) && (ninja.birthday.day == current_time.day) && not is_nil(ninja.user) end) + |> Enum.filter(fn ninja -> + ninja.birthday.month == current_time.month && ninja.birthday.day == current_time.day && + not is_nil(ninja.user) + end) |> Enum.map(fn ninja -> ninja.user end) - # |> Enum.filter(fn ninja -> (Date.compare(ninja.birthday, current_time) == :eq) end) - |> send_email(fn user -> EventsEmails.ninja_birthday_email(user.ninja, to: Accounts.get_guardian_email_by_ninja(ninja: user)) end) + |> send_email(fn user -> + EventsEmails.ninja_birthday_email(user.ninja, + to: Accounts.get_guardian_email_by_ninja(ninja: user) + ) + end) end end diff --git a/lib/bokken_web/controllers/ninja_controller.ex b/lib/bokken_web/controllers/ninja_controller.ex index e44ca086..e53a6b82 100644 --- a/lib/bokken_web/controllers/ninja_controller.ex +++ b/lib/bokken_web/controllers/ninja_controller.ex @@ -85,5 +85,4 @@ defmodule BokkenWeb.NinjaController do send_resp(conn, :no_content, "") end end - end diff --git a/lib/bokken_web/emails/event_emails.ex b/lib/bokken_web/emails/event_emails.ex index dfccb9bf..0dba6dfd 100644 --- a/lib/bokken_web/emails/event_emails.ex +++ b/lib/bokken_web/emails/event_emails.ex @@ -55,10 +55,9 @@ defmodule BokkenWeb.EventsEmails do end def ninja_birthday_email(ninja, to: email) do - frontend_url = Application.fetch_env!(:bokken, BokkenWeb.Endpoint)[:frontend_url] - base_email(to: email) |> subject("[CoderDojo Braga] O Dojo deseja-te parabéns!") + |> assign(:ninja, ninja) |> render_body(:ninja_birthday) end diff --git a/lib/bokken_web/router.ex b/lib/bokken_web/router.ex index 4b888430..05b06da2 100644 --- a/lib/bokken_web/router.ex +++ b/lib/bokken_web/router.ex @@ -100,8 +100,6 @@ defmodule BokkenWeb.Router do post "/notify_signup", EventController, :notify_signup post "/notify_selected", EventController, :notify_selected - # post "/notify_ninja_birthday", NinjaController, :notify_ninja_birthday - resources "/bot", BotController, except: [:new, :edit] end diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex index 9e0355c0..fa018099 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.html.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.html.eex @@ -10,6 +10,30 @@
 
+ +
+
+

+ 🥳 Aniversário 🥳 +

+
+
+ +
+
+

+ Olá! 👋 +

+
+
+ +
+
+

+ O CoderDojo Braga deseja-te um dia feliz e um ótimo aniversário. Esperamos por ti na pŕoxima sessão! 😄 +

+
+
diff --git a/lib/bokken_web/templates/email/ninja_birthday.text.eex b/lib/bokken_web/templates/email/ninja_birthday.text.eex index 8ce720eb..94534073 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.text.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.text.eex @@ -1,5 +1,3 @@ -Olá 👋 +Olá! 👋 -Infelizmente, informamos que o(a) ninjanão foi selecionado(a) para participar na próxima sessão. - -Agradecemos o interesse em participar no Coderdojo Braga. Tentaremos que o seu/ a sua ninja possa participar em sessões futuras. \ No newline at end of file +O CoderDojo Braga deseja-te um dia feliz e um ótimo aniversário. Esperamos por ti na próxima sessão! 😄 \ No newline at end of file From db40a6759909cff0ad85cb076c08cead920e92d2 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 20 Jan 2023 23:30:27 +0000 Subject: [PATCH 04/21] Corrections in lint the code --- lib/bokken/periodically.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex index a9920bba..1a7b630a 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/periodically.ex @@ -1,4 +1,7 @@ defmodule Bokken.Periodically do + @moduledoc """ + Executes a task periodically. + """ use GenServer alias Bokken.Accounts @@ -22,11 +25,11 @@ defmodule Bokken.Periodically do {:noreply, state} end - defp schedule_work() do + defp schedule_work do Process.send_after(self(), :work, @one_day) end - defp notify_ninja_birthday() do + defp notify_ninja_birthday do ninjas = Accounts.list_ninjas([:user]) current_time = Date.utc_today() From 4859d6a0bd8528885d1504c56fdc0ee4b9965df3 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sat, 4 Mar 2023 20:56:00 +0000 Subject: [PATCH 05/21] Add ninjas reference --- lib/bokken_web/templates/email/ninja_birthday.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex index fa018099..3b3d5f77 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.html.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.html.eex @@ -22,7 +22,7 @@

- Olá! 👋 + Olá, <%= @ninja.first_name %>! 👋

From 247f43a744afc5e63b4264f8f1a6bf28e12d5268 Mon Sep 17 00:00:00 2001 From: Pedro Pereira <109802203+pedrofp4444@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:34:59 +0000 Subject: [PATCH 06/21] Update lib/bokken_web/templates/email/ninja_birthday.html.eex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nelson Estevão --- lib/bokken_web/templates/email/ninja_birthday.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex index fa018099..153a0100 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.html.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.html.eex @@ -30,7 +30,7 @@

- O CoderDojo Braga deseja-te um dia feliz e um ótimo aniversário. Esperamos por ti na pŕoxima sessão! 😄 + O CoderDojo Braga deseja-te um feliz aniversário! 🎂 Esperamos por ti na proxima sessão! 😄

From 79550aa93d710a91e4e1b7e22edbd1e26d92b9ab Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sat, 4 Mar 2023 23:48:35 +0000 Subject: [PATCH 07/21] Corrected ninja assign --- lib/bokken_web/templates/email/ninja_birthday.html.eex | 2 +- lib/bokken_web/templates/email/ninja_birthday.text.eex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bokken_web/templates/email/ninja_birthday.html.eex b/lib/bokken_web/templates/email/ninja_birthday.html.eex index 3b3d5f77..acc0b7a3 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.html.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.html.eex @@ -30,7 +30,7 @@

- O CoderDojo Braga deseja-te um dia feliz e um ótimo aniversário. Esperamos por ti na pŕoxima sessão! 😄 + O CoderDojo Braga deseja-te um feliz aniversário! 🎂 Esperamos por ti na próxima sessão! 😄

diff --git a/lib/bokken_web/templates/email/ninja_birthday.text.eex b/lib/bokken_web/templates/email/ninja_birthday.text.eex index 94534073..8dbb7522 100644 --- a/lib/bokken_web/templates/email/ninja_birthday.text.eex +++ b/lib/bokken_web/templates/email/ninja_birthday.text.eex @@ -1,3 +1,3 @@ -Olá! 👋 +Olá, <%= @ninja.first_name %>! 👋 -O CoderDojo Braga deseja-te um dia feliz e um ótimo aniversário. Esperamos por ti na próxima sessão! 😄 \ No newline at end of file +O CoderDojo Braga deseja-te um feliz aniversário! 🎂 Esperamos por ti na próxima sessão! 😄 \ No newline at end of file From b60e09fb0119c4323df741f28221cb4e99978464 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sun, 5 Mar 2023 00:37:02 +0000 Subject: [PATCH 08/21] Change module name --- lib/bokken/application.ex | 4 ++-- lib/bokken/periodically.ex | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index 5490be18..66104dd9 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -18,8 +18,8 @@ defmodule Bokken.Application do BokkenWeb.Endpoint, # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} - Bokken.Periodically - # Executes a task periodically + Bokken.BirthdayNotifier + # Executes a task periodically to notify Ninjas on their birthday ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex index 1a7b630a..691ef4cf 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/periodically.ex @@ -1,6 +1,6 @@ -defmodule Bokken.Periodically do +defmodule Bokken.BirthdayNotifier do @moduledoc """ - Executes a task periodically. + Executes a task periodically to notify Ninjas on their birthday. """ use GenServer From e3b7c6b17f61ee03e44474010a722c2095c2a622 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sun, 5 Mar 2023 00:51:31 +0000 Subject: [PATCH 09/21] Format code --- lib/bokken/accounts.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken/accounts.ex b/lib/bokken/accounts.ex index c86cb037..12af5f0b 100644 --- a/lib/bokken/accounts.ex +++ b/lib/bokken/accounts.ex @@ -331,7 +331,7 @@ defmodule Bokken.Accounts do [%Ninja{}, ...] """ - + def list_ninjas(preloads) when is_list(preloads) do Ninja |> Repo.all() From 1f641d4abea532aa816136a088f2dcae4126080f Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sun, 5 Mar 2023 01:17:00 +0000 Subject: [PATCH 10/21] Config :quantum --- config/config.exs | 6 ++++++ lib/bokken/application.ex | 4 +++- lib/bokken/scheduler.ex | 3 +++ mix.exs | 5 ++++- 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 lib/bokken/scheduler.ex diff --git a/config/config.exs b/config/config.exs index f235ca25..eac12c71 100644 --- a/config/config.exs +++ b/config/config.exs @@ -53,6 +53,12 @@ config :logger, :console, # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason +config :bokken, Bokken.Scheduler, + jobs: [ + # Every midnight + {"@daily", {Heartbeat, :send, []}} + ] + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index 66104dd9..a093b294 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -18,8 +18,10 @@ defmodule Bokken.Application do BokkenWeb.Endpoint, # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} - Bokken.BirthdayNotifier + Bokken.BirthdayNotifier, # Executes a task periodically to notify Ninjas on their birthday + Bokken.Scheduler + # Operates cronjob tasks using :quantum ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex new file mode 100644 index 00000000..4596a79c --- /dev/null +++ b/lib/bokken/scheduler.ex @@ -0,0 +1,3 @@ +defmodule Bokken.Scheduler do + use Quantum, otp_app: :your_app +end diff --git a/mix.exs b/mix.exs index bc1b89fb..1bf0c15f 100644 --- a/mix.exs +++ b/mix.exs @@ -93,7 +93,10 @@ defmodule Bokken.MixProject do # tools {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, - {:ex_doc, "~> 0.28", only: [:dev], runtime: false} + {:ex_doc, "~> 0.28", only: [:dev], runtime: false}, + + # periodically + {:quantum, "~> 3.0"} ] end From 25e927c1c5bd9dd97fe4182e4969604f58597eb3 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Sun, 5 Mar 2023 01:41:20 +0000 Subject: [PATCH 11/21] Config :quantum --- config/config.exs | 2 +- lib/bokken/periodically.ex | 22 ---------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/config/config.exs b/config/config.exs index eac12c71..1520ac01 100644 --- a/config/config.exs +++ b/config/config.exs @@ -56,7 +56,7 @@ config :phoenix, :json_library, Jason config :bokken, Bokken.Scheduler, jobs: [ # Every midnight - {"@daily", {Heartbeat, :send, []}} + {"@daily", {BirthdayNotifier, :notify_ninja_birthday, []}} ] # Import environment specific config. This must remain at the bottom diff --git a/lib/bokken/periodically.ex b/lib/bokken/periodically.ex index 691ef4cf..5b24b301 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/periodically.ex @@ -2,33 +2,11 @@ defmodule Bokken.BirthdayNotifier do @moduledoc """ Executes a task periodically to notify Ninjas on their birthday. """ - use GenServer alias Bokken.Accounts alias BokkenWeb.EventsEmails import Bokken.Events.EventAdmin - @one_day 24 * 60 * 60 * 1000 - - def start_link(_opts) do - GenServer.start_link(__MODULE__, %{}) - end - - def init(state) do - schedule_work() - {:ok, state} - end - - def handle_info(:work, state) do - notify_ninja_birthday() - schedule_work() - {:noreply, state} - end - - defp schedule_work do - Process.send_after(self(), :work, @one_day) - end - defp notify_ninja_birthday do ninjas = Accounts.list_ninjas([:user]) current_time = Date.utc_today() From 037c24d3462449224b47a55a3ab184ecd8b1dc22 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Tue, 7 Mar 2023 09:09:04 +0000 Subject: [PATCH 12/21] Fix :quantum config --- lib/bokken/application.ex | 2 -- lib/bokken/scheduler.ex | 2 +- lib/bokken_web/emails/event_emails.ex | 2 +- mix.exs | 8 ++++---- mix.lock | 4 ++++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index a093b294..0b1b5be1 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -18,8 +18,6 @@ defmodule Bokken.Application do BokkenWeb.Endpoint, # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} - Bokken.BirthdayNotifier, - # Executes a task periodically to notify Ninjas on their birthday Bokken.Scheduler # Operates cronjob tasks using :quantum ] diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex index 4596a79c..8cb6bb39 100644 --- a/lib/bokken/scheduler.ex +++ b/lib/bokken/scheduler.ex @@ -1,3 +1,3 @@ defmodule Bokken.Scheduler do - use Quantum, otp_app: :your_app + use Quantum, otp_app: :bokken end diff --git a/lib/bokken_web/emails/event_emails.ex b/lib/bokken_web/emails/event_emails.ex index 5f2ae3e0..186dc091 100644 --- a/lib/bokken_web/emails/event_emails.ex +++ b/lib/bokken_web/emails/event_emails.ex @@ -48,7 +48,7 @@ defmodule BokkenWeb.EventsEmails do def ninja_birthday_email(ninja, to: email) do base_email(to: email) - |> subject("[CoderDojo Braga] O Dojo deseja-te parabéns!") + |> subject("O CoderDojo Braga deseja-te um feliz aniversário! 🎂") |> assign(:ninja, ninja) |> render_body(:ninja_birthday) end diff --git a/mix.exs b/mix.exs index 1bf0c15f..5ed6833e 100644 --- a/mix.exs +++ b/mix.exs @@ -68,6 +68,9 @@ defmodule Bokken.MixProject do {:plug_cowboy, "~> 2.5"}, {:cors_plug, "~> 3.0"}, + # cronjobs + {:quantum, "~> 3.0"}, + # utilities {:gettext, "~> 0.22.1"}, {:jason, "~> 1.3"}, @@ -93,10 +96,7 @@ defmodule Bokken.MixProject do # tools {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, {:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false}, - {:ex_doc, "~> 0.28", only: [:dev], runtime: false}, - - # periodically - {:quantum, "~> 3.0"} + {:ex_doc, "~> 0.28", only: [:dev], runtime: false} ] end diff --git a/mix.lock b/mix.lock index fb175b65..11bd9947 100644 --- a/mix.lock +++ b/mix.lock @@ -12,6 +12,7 @@ "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, "credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"}, + "crontab": {:hex, :crontab, "1.1.13", "3bad04f050b9f7f1c237809e42223999c150656a6b2afbbfef597d56df2144c5", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "d67441bec989640e3afb94e123f45a2bc42d76e02988c9613885dc3d01cf7085"}, "db_connection": {:hex, :db_connection, "2.4.3", "3b9aac9f27347ec65b271847e6baeb4443d8474289bd18c1d6f4de655b70c94d", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c127c15b0fa6cfb32eed07465e05da6c815b032508d4ed7c116122871df73c12"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"}, @@ -26,6 +27,7 @@ "expo": {:hex, :expo, "0.4.0", "bbe4bf455e2eb2ebd2f1e7d83530ce50fb9990eb88fc47855c515bfdf1c6626f", [:mix], [], "hexpm", "a8ed1683ec8b7c7fa53fd7a41b2c6935f539168a6bb0616d7fd6b58a36f3abf2"}, "faker": {:hex, :faker, "0.17.0", "671019d0652f63aefd8723b72167ecdb284baf7d47ad3a82a15e9b8a6df5d1fa", [:mix], [], "hexpm", "a7d4ad84a93fd25c5f5303510753789fc2433ff241bf3b4144d3f6f291658a6a"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "gen_stage": {:hex, :gen_stage, "1.2.0", "ee49244b57803f54bdab08a60a927e1b4e5bb5d635c52eca0f376a0673af3f8c", [:mix], [], "hexpm", "c3e40992c72e74d9c4eda16d7515bf32c9e7b634e827ab11091fff3290f7b503"}, "gettext": {:hex, :gettext, "0.22.1", "e7942988383c3d9eed4bdc22fc63e712b655ae94a672a27e4900e3d4a2c43581", [:mix], [{:expo, "~> 0.4.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "ad105b8dab668ee3f90c0d3d94ba75e9aead27a62495c101d94f2657a190ac5d"}, "guardian": {:hex, :guardian, "2.3.1", "2b2d78dc399a7df182d739ddc0e566d88723299bfac20be36255e2d052fd215d", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "bbe241f9ca1b09fad916ad42d6049d2600bbc688aba5b3c4a6c82592a54274c3"}, "hackney": {:hex, :hackney, "1.18.1", "f48bf88f521f2a229fc7bae88cf4f85adc9cd9bcf23b5dc8eb6a1788c662c4f6", [:rebar3], [{:certifi, "~>2.9.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a4ecdaff44297e9b5894ae499e9a070ea1888c84afdd1fd9b7b2bc384950128e"}, @@ -54,12 +56,14 @@ "plug_cowboy": {:hex, :plug_cowboy, "2.6.0", "d1cf12ff96a1ca4f52207c5271a6c351a4733f413803488d75b70ccf44aebec2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "073cf20b753ce6682ed72905cd62a2d4bd9bad1bf9f7feb02a1b8e525bd94fa6"}, "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"}, "postgrex": {:hex, :postgrex, "0.16.5", "fcc4035cc90e23933c5d69a9cd686e329469446ef7abba2cf70f08e2c4b69810", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "edead639dc6e882618c01d8fc891214c481ab9a3788dfe38dd5e37fd1d5fb2e8"}, + "quantum": {:hex, :quantum, "3.5.0", "8d2c5ba68c55991e8975aca368e3ab844ba01f4b87c4185a7403280e2c99cf34", [:mix], [{:crontab, "~> 1.1", [hex: :crontab, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.14 or ~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:telemetry_registry, "~> 0.2", [hex: :telemetry_registry, repo: "hexpm", optional: false]}], "hexpm", "cab737d1d9779f43cb1d701f46dd05ea58146fd96238d91c9e0da662c1982bb6"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, "swoosh": {:hex, :swoosh, "1.9.1", "0a5d7bf9954eb41d7e55525bc0940379982b090abbaef67cd8e1fd2ed7f8ca1a", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "76dffff3ffcab80f249d5937a592eaef7cc49ac6f4cdd27e622868326ed6371e"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"}, "telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"}, + "telemetry_registry": {:hex, :telemetry_registry, "0.3.0", "6768f151ea53fc0fbca70dbff5b20a8d663ee4e0c0b2ae589590e08658e76f1e", [:mix, :rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "492e2adbc609f3e79ece7f29fec363a97a2c484ac78a83098535d6564781e917"}, "timex": {:hex, :timex, "3.7.9", "790cdfc4acfce434e442f98c02ea6d84d0239073bfd668968f82ac63e9a6788d", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "64691582e5bb87130f721fc709acfb70f24405833998fabf35be968984860ce1"}, "tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, From 4fa573f5ae2c504079c67ecfd2a6b94e27ba82ed Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Tue, 7 Mar 2023 09:17:34 +0000 Subject: [PATCH 13/21] Fix file name --- lib/bokken/{periodically.ex => birthdaynotifier.ex} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename lib/bokken/{periodically.ex => birthdaynotifier.ex} (95%) diff --git a/lib/bokken/periodically.ex b/lib/bokken/birthdaynotifier.ex similarity index 95% rename from lib/bokken/periodically.ex rename to lib/bokken/birthdaynotifier.ex index 5b24b301..3d7fd5dd 100644 --- a/lib/bokken/periodically.ex +++ b/lib/bokken/birthdaynotifier.ex @@ -7,7 +7,7 @@ defmodule Bokken.BirthdayNotifier do alias BokkenWeb.EventsEmails import Bokken.Events.EventAdmin - defp notify_ninja_birthday do + def notify_ninja_birthday do ninjas = Accounts.list_ninjas([:user]) current_time = Date.utc_today() From 05233037a76e6acf928396e3211035eb28f0a44b Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Tue, 7 Mar 2023 09:23:35 +0000 Subject: [PATCH 14/21] Lint code --- lib/bokken/scheduler.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex index 8cb6bb39..5b26dec0 100644 --- a/lib/bokken/scheduler.ex +++ b/lib/bokken/scheduler.ex @@ -1,3 +1,7 @@ defmodule Bokken.Scheduler do + @moduledoc """ + Standard module to run a cronjob. + """ + use Quantum, otp_app: :bokken end From 1646da1bcd0279666f22d813688c8d2f7d1c2f2f Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Tue, 7 Mar 2023 09:40:29 +0000 Subject: [PATCH 15/21] Prepare new push --- lib/bokken/scheduler.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex index 5b26dec0..ab71635e 100644 --- a/lib/bokken/scheduler.ex +++ b/lib/bokken/scheduler.ex @@ -3,5 +3,5 @@ defmodule Bokken.Scheduler do Standard module to run a cronjob. """ - use Quantum, otp_app: :bokken + use Quantum, otp_app: :bokkenasdasdads end From 2261aecbfb7a121f8efc93b04fce51d8e90159cd Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Tue, 7 Mar 2023 09:41:18 +0000 Subject: [PATCH 16/21] Tests passing locally --- lib/bokken/scheduler.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex index ab71635e..5b26dec0 100644 --- a/lib/bokken/scheduler.ex +++ b/lib/bokken/scheduler.ex @@ -3,5 +3,5 @@ defmodule Bokken.Scheduler do Standard module to run a cronjob. """ - use Quantum, otp_app: :bokkenasdasdads + use Quantum, otp_app: :bokken end From d0f0500ea39c8b0fe2217807de1a3be8ea291cc5 Mon Sep 17 00:00:00 2001 From: Pedro Pereira <109802203+pedrofp4444@users.noreply.github.com> Date: Wed, 8 Mar 2023 11:26:38 +0000 Subject: [PATCH 17/21] Update lib/bokken/events/event_admin.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mário Rodrigues <93675410+MarioRodrigues10@users.noreply.github.com> --- lib/bokken/events/event_admin.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken/events/event_admin.ex b/lib/bokken/events/event_admin.ex index 88600fcb..9a4069ec 100644 --- a/lib/bokken/events/event_admin.ex +++ b/lib/bokken/events/event_admin.ex @@ -50,7 +50,7 @@ defmodule Bokken.Events.EventAdmin do def send_email(users, email) do users - |> List.foldl( + |> Enum.reduce( %{success: [], fail: []}, fn user, accumulator -> case Mailer.deliver(email.(user)) do From 775591efb05d82b6165d92b2a2b4e64f606fef8a Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 10 Mar 2023 14:33:49 +0000 Subject: [PATCH 18/21] Change file name and improve code --- lib/bokken/accounts.ex | 7 ++----- lib/bokken/application.ex | 2 +- lib/bokken/{birthdaynotifier.ex => birthday_notifier.ex} | 0 3 files changed, 3 insertions(+), 6 deletions(-) rename lib/bokken/{birthdaynotifier.ex => birthday_notifier.ex} (100%) diff --git a/lib/bokken/accounts.ex b/lib/bokken/accounts.ex index 54cec105..7bf343b0 100644 --- a/lib/bokken/accounts.ex +++ b/lib/bokken/accounts.ex @@ -512,13 +512,10 @@ defmodule Bokken.Accounts do end def get_guardian_email_by_ninja(ninja: user) do - user = user |> Repo.preload(:ninja) - - guardian = get_guardian!(user.ninja.guardian_id, [:user]) - - guardian.user.email + |> then(fn user -> get_guardian!(user.ninja.guardian_id, [:user]) end) + |> then(fn guardian -> guardian.user.email end) end alias Bokken.Accounts.Organizer diff --git a/lib/bokken/application.ex b/lib/bokken/application.ex index 0b1b5be1..77d3f440 100644 --- a/lib/bokken/application.ex +++ b/lib/bokken/application.ex @@ -18,8 +18,8 @@ defmodule Bokken.Application do BokkenWeb.Endpoint, # Start a worker by calling: Bokken.Worker.start_link(arg) # {Bokken.Worker, arg} - Bokken.Scheduler # Operates cronjob tasks using :quantum + Bokken.Scheduler ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/bokken/birthdaynotifier.ex b/lib/bokken/birthday_notifier.ex similarity index 100% rename from lib/bokken/birthdaynotifier.ex rename to lib/bokken/birthday_notifier.ex From 6a9146a482eee952dbcebafdbfa79e2a05ee5f37 Mon Sep 17 00:00:00 2001 From: pedrofp4444 Date: Fri, 10 Mar 2023 20:13:11 +0000 Subject: [PATCH 19/21] Format code --- lib/bokken/accounts.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bokken/accounts.ex b/lib/bokken/accounts.ex index 7bf343b0..6c7d0e2f 100644 --- a/lib/bokken/accounts.ex +++ b/lib/bokken/accounts.ex @@ -512,10 +512,10 @@ defmodule Bokken.Accounts do end def get_guardian_email_by_ninja(ninja: user) do - user - |> Repo.preload(:ninja) - |> then(fn user -> get_guardian!(user.ninja.guardian_id, [:user]) end) - |> then(fn guardian -> guardian.user.email end) + user + |> Repo.preload(:ninja) + |> then(fn user -> get_guardian!(user.ninja.guardian_id, [:user]) end) + |> then(fn guardian -> guardian.user.email end) end alias Bokken.Accounts.Organizer From 4b37245ad0e6416a9f43f9163b4539e7c4b48f9d Mon Sep 17 00:00:00 2001 From: Pedro Pereira <109802203+pedrofp4444@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:18:53 +0000 Subject: [PATCH 20/21] Update lib/bokken/birthday_notifier.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nelson Estevão --- lib/bokken/birthday_notifier.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bokken/birthday_notifier.ex b/lib/bokken/birthday_notifier.ex index 3d7fd5dd..d7d54284 100644 --- a/lib/bokken/birthday_notifier.ex +++ b/lib/bokken/birthday_notifier.ex @@ -7,7 +7,7 @@ defmodule Bokken.BirthdayNotifier do alias BokkenWeb.EventsEmails import Bokken.Events.EventAdmin - def notify_ninja_birthday do + def send_happy_birthday_ninjas do ninjas = Accounts.list_ninjas([:user]) current_time = Date.utc_today() From 6a0e9c884e27ebdcc86122464a34d4f3a36a7c19 Mon Sep 17 00:00:00 2001 From: Pedro Pereira <109802203+pedrofp4444@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:19:02 +0000 Subject: [PATCH 21/21] Update lib/bokken/scheduler.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nelson Estevão --- lib/bokken/scheduler.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/bokken/scheduler.ex b/lib/bokken/scheduler.ex index 5b26dec0..b751df49 100644 --- a/lib/bokken/scheduler.ex +++ b/lib/bokken/scheduler.ex @@ -2,6 +2,5 @@ defmodule Bokken.Scheduler do @moduledoc """ Standard module to run a cronjob. """ - use Quantum, otp_app: :bokken end