diff --git a/Gemfile b/Gemfile index 2df9ea4a..3df8c9bf 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ gem "bcrypt", "~> 3.1.7" # Reduces boot times through caching; required in config/boot.rb gem "bootsnap", ">= 1.4.4", require: false +gem "sidekiq" group :development, :test do gem "byebug", platforms: %i[mri mingw x64_mingw] @@ -49,6 +50,7 @@ group :development do gem "web-console", ">= 4.1.0" # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md + gem "letter_opener" gem "listen", "~> 3.3" gem "rack-mini-profiler", "~> 2.0" # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring diff --git a/Gemfile.lock b/Gemfile.lock index d49ce45b..7d4de491 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -83,6 +83,7 @@ GEM xpath (~> 3.2) coderay (1.1.3) concurrent-ruby (1.2.2) + connection_pool (2.4.1) crass (1.0.6) date (3.3.3) enumerize (2.7.0) @@ -111,6 +112,10 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) language_server-protocol (3.17.0.3) + launchy (2.5.2) + addressable (~> 2.8) + letter_opener (1.8.1) + launchy (>= 2.2, < 3) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -194,6 +199,8 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) + redis-client (0.18.0) + connection_pool regexp_parser (2.8.1) rexml (3.2.6) rubocop (1.56.4) @@ -243,6 +250,11 @@ GEM rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) semantic_range (3.0.0) + sidekiq (7.1.6) + concurrent-ruby (< 2) + connection_pool (>= 2.3.0) + rack (>= 2.2.4) + redis-client (>= 0.14.0) spring (4.1.1) sprockets (4.2.1) concurrent-ruby (~> 1.0) @@ -295,6 +307,7 @@ DEPENDENCIES interactor (~> 3.0) jbuilder (~> 2.7) kaminari + letter_opener listen (~> 3.3) pg (~> 1.1) pry @@ -310,6 +323,7 @@ DEPENDENCIES rubocop-thread_safety sass-rails (>= 6) selenium-webdriver (>= 4.0.0.rc1) + sidekiq spring turbolinks (~> 5) tzinfo-data diff --git a/app/interactors/projects/create.rb b/app/interactors/projects/create.rb index 6a70d45e..af65b269 100644 --- a/app/interactors/projects/create.rb +++ b/app/interactors/projects/create.rb @@ -2,7 +2,14 @@ module Projects class Create include Interactor::Organizer + delegate :project, :user, to: :context + organize Projects::Save, Projects::Create::CreateOwner + + after do + ProjectMailer.project_created(project, user).deliver_later + Projects::CreateDefaultTasksJob.perform_async(project.id) + end end end diff --git a/app/jobs/projects/create_default_tasks_job.rb b/app/jobs/projects/create_default_tasks_job.rb new file mode 100644 index 00000000..0a28c72c --- /dev/null +++ b/app/jobs/projects/create_default_tasks_job.rb @@ -0,0 +1,17 @@ +module Projects + class CreateDefaultTasksJob + include Sidekiq::Worker + + sidekiq_options queue: :default, retry: 3 + + def perform(project_id) + project = Project.find(project_id) + + project.tasks.create( + [ + { name: "Your first task", status: :unstarted, deadline_at: 1.week.from_now } + ] + ) + end + end +end diff --git a/app/mailers/project_mailer.rb b/app/mailers/project_mailer.rb new file mode 100644 index 00000000..c84e50e7 --- /dev/null +++ b/app/mailers/project_mailer.rb @@ -0,0 +1,7 @@ +class ProjectMailer < ApplicationMailer + def project_created(project, user) + @project = project + + mail(to: user.email) + end +end diff --git a/app/views/project_mailer/project_created.html.erb b/app/views/project_mailer/project_created.html.erb new file mode 100644 index 00000000..61e11ba6 --- /dev/null +++ b/app/views/project_mailer/project_created.html.erb @@ -0,0 +1,2 @@ +

New project created.

+

Congratulations! You have become the owner of a new project -- "<%= @project.name %>"!

diff --git a/app/views/project_mailer/project_created.txt.erb b/app/views/project_mailer/project_created.txt.erb new file mode 100644 index 00000000..1f1059e6 --- /dev/null +++ b/app/views/project_mailer/project_created.txt.erb @@ -0,0 +1 @@ +Congratulations! You have become the owner of a new project -- "<%= @project.name %>"! diff --git a/config/environments/development.rb b/config/environments/development.rb index 0a5aa39c..39fa73fc 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,6 @@ require "active_support/core_ext/integer/time" -Rails.application.configure do +Rails.application.configure do # rubocop:disable Metrics/BlockLength # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time @@ -73,4 +73,8 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + + config.action_mailer.delivery_method = :letter_opener + config.action_mailer.perform_deliveries = true + config.active_job.queue_adapter = :sidekiq end diff --git a/config/routes.rb b/config/routes.rb index ed05b960..863b13eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ +require "sidekiq/web" + Rails.application.routes.draw do + mount Sidekiq::Web => "/sidekiq" + root "projects#index" get "login", to: "sessions#new", as: :login post "login", to: "sessions#create"