Commit 7f214cee authored by Valery Sizov's avatar Valery Sizov Committed by Valery Sizov

Migrate mailers to ActiveJob

parent 3e0fe276
source "https://rubygems.org" source "https://rubygems.org"
gem 'rails', '4.2.4' gem 'rails', '4.2.4'
gem 'rails-deprecated_sanitizer', '~> 1.0.3'
# Responders respond_to and respond_with # Responders respond_to and respond_with
gem 'responders', '~> 2.0' gem 'responders', '~> 2.0'
......
...@@ -930,6 +930,7 @@ DEPENDENCIES ...@@ -930,6 +930,7 @@ DEPENDENCIES
rack-cors (~> 0.4.0) rack-cors (~> 0.4.0)
rack-oauth2 (~> 1.2.1) rack-oauth2 (~> 1.2.1)
rails (= 4.2.4) rails (= 4.2.4)
rails-deprecated_sanitizer (~> 1.0.3)
raphael-rails (~> 2.1.2) raphael-rails (~> 2.1.2)
rblineprof rblineprof
rdoc (~> 3.6) rdoc (~> 3.6)
......
web: bundle exec unicorn_rails -p ${PORT:="3000"} -E ${RAILS_ENV:="development"} -c ${UNICORN_CONFIG:="config/unicorn.rb"} web: bundle exec unicorn_rails -p ${PORT:="3000"} -E ${RAILS_ENV:="development"} -c ${UNICORN_CONFIG:="config/unicorn.rb"}
worker: bundle exec sidekiq -q post_receive -q mailer -q archive_repo -q system_hook -q project_web_hook -q gitlab_shell -q incoming_email -q runner -q common -q default worker: bundle exec sidekiq -q post_receive -q mailer -q archive_repo -q system_hook -q project_web_hook -q gitlab_shell -q incoming_email -q runner -q common -q mailers -q default
# mail_room: bundle exec mail_room -q -c config/mail_room.yml # mail_room: bundle exec mail_room -q -c config/mail_room.yml
...@@ -10,7 +10,7 @@ class AbuseReportsController < ApplicationController ...@@ -10,7 +10,7 @@ class AbuseReportsController < ApplicationController
if @abuse_report.save if @abuse_report.save
if current_application_settings.admin_notification_email.present? if current_application_settings.admin_notification_email.present?
AbuseReportMailer.delay.notify(@abuse_report.id) AbuseReportMailer.deliver_later.notify(@abuse_report.id)
end end
message = "Thank you for your report. A GitLab administrator will look into it shortly." message = "Thank you for your report. A GitLab administrator will look into it shortly."
......
...@@ -8,10 +8,6 @@ class BaseMailer < ActionMailer::Base ...@@ -8,10 +8,6 @@ class BaseMailer < ActionMailer::Base
default from: Proc.new { default_sender_address.format } default from: Proc.new { default_sender_address.format }
default reply_to: Proc.new { default_reply_to_address.format } default reply_to: Proc.new { default_reply_to_address.format }
def self.delay
delay_for(2.seconds)
end
def can? def can?
Ability.abilities.allowed?(current_user, action, subject) Ability.abilities.allowed?(current_user, action, subject)
end end
......
...@@ -78,7 +78,7 @@ module Ci ...@@ -78,7 +78,7 @@ module Ci
end end
def mailer def mailer
Ci::Notify.delay Ci::Notify.deliver_later
end end
end end
end end
...@@ -13,14 +13,14 @@ class NotificationService ...@@ -13,14 +13,14 @@ class NotificationService
# even if user disabled notifications # even if user disabled notifications
def new_key(key) def new_key(key)
if key.user if key.user
mailer.new_ssh_key_email(key.id) mailer.new_ssh_key_email(key.id).deliver_later
end end
end end
# Always notify user about email added to profile # Always notify user about email added to profile
def new_email(email) def new_email(email)
if email.user if email.user
mailer.new_email_email(email.id) mailer.new_email_email(email.id).deliver_later
end end
end end
...@@ -79,17 +79,27 @@ class NotificationService ...@@ -79,17 +79,27 @@ class NotificationService
end end
def merge_mr(merge_request, current_user) def merge_mr(merge_request, current_user)
close_resource_email(merge_request, merge_request.target_project, current_user, 'merged_merge_request_email') close_resource_email(
merge_request,
merge_request.target_project,
current_user,
'merged_merge_request_email'
)
end end
def reopen_mr(merge_request, current_user) def reopen_mr(merge_request, current_user)
reopen_resource_email(merge_request, merge_request.target_project, current_user, 'merge_request_status_email', 'reopened') reopen_resource_email(
merge_request,
merge_request.target_project,
current_user, 'merge_request_status_email',
'reopened'
)
end end
# Notify new user with email after creation # Notify new user with email after creation
def new_user(user, token = nil) def new_user(user, token = nil)
# Don't email omniauth created users # Don't email omniauth created users
mailer.new_user_email(user.id, token) unless user.identities.any? mailer.new_user_email(user.id, token).deliver_later unless user.identities.any?
end end
# Notify users on new note in system # Notify users on new note in system
...@@ -140,48 +150,58 @@ class NotificationService ...@@ -140,48 +150,58 @@ class NotificationService
notify_method = "note_#{note.noteable_type.underscore}_email".to_sym notify_method = "note_#{note.noteable_type.underscore}_email".to_sym
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(notify_method, recipient.id, note.id) mailer.send(notify_method, recipient.id, note.id).deliver_later
end end
end end
def invite_project_member(project_member, token) def invite_project_member(project_member, token)
mailer.project_member_invited_email(project_member.id, token) mailer.project_member_invited_email(project_member.id, token).deliver_later
end end
def accept_project_invite(project_member) def accept_project_invite(project_member)
mailer.project_invite_accepted_email(project_member.id) mailer.project_invite_accepted_email(project_member.id).deliver_later
end end
def decline_project_invite(project_member) def decline_project_invite(project_member)
mailer.project_invite_declined_email(project_member.project.id, project_member.invite_email, project_member.access_level, project_member.created_by_id) mailer.project_invite_declined_email(
project_member.project.id,
project_member.invite_email,
project_member.access_level,
project_member.created_by_id
).deliver_later
end end
def new_project_member(project_member) def new_project_member(project_member)
mailer.project_access_granted_email(project_member.id) mailer.project_access_granted_email(project_member.id).deliver_later
end end
def update_project_member(project_member) def update_project_member(project_member)
mailer.project_access_granted_email(project_member.id) mailer.project_access_granted_email(project_member.id).deliver_later
end end
def invite_group_member(group_member, token) def invite_group_member(group_member, token)
mailer.group_member_invited_email(group_member.id, token) mailer.group_member_invited_email(group_member.id, token).deliver_later
end end
def accept_group_invite(group_member) def accept_group_invite(group_member)
mailer.group_invite_accepted_email(group_member.id) mailer.group_invite_accepted_email(group_member.id).deliver_later
end end
def decline_group_invite(group_member) def decline_group_invite(group_member)
mailer.group_invite_declined_email(group_member.group.id, group_member.invite_email, group_member.access_level, group_member.created_by_id) mailer.group_invite_declined_email(
group_member.group.id,
group_member.invite_email,
group_member.access_level,
group_member.created_by_id
).deliver_later
end end
def new_group_member(group_member) def new_group_member(group_member)
mailer.group_access_granted_email(group_member.id) mailer.group_access_granted_email(group_member.id).deliver_later
end end
def update_group_member(group_member) def update_group_member(group_member)
mailer.group_access_granted_email(group_member.id) mailer.group_access_granted_email(group_member.id).deliver_later
end end
def project_was_moved(project, old_path_with_namespace) def project_was_moved(project, old_path_with_namespace)
...@@ -189,7 +209,11 @@ class NotificationService ...@@ -189,7 +209,11 @@ class NotificationService
recipients = reject_muted_users(recipients, project) recipients = reject_muted_users(recipients, project)
recipients.each do |recipient| recipients.each do |recipient|
mailer.project_was_moved_email(project.id, recipient.id, old_path_with_namespace) mailer.project_was_moved_email(
project.id,
recipient.id,
old_path_with_namespace
).deliver_later
end end
end end
...@@ -339,7 +363,7 @@ class NotificationService ...@@ -339,7 +363,7 @@ class NotificationService
recipients = build_recipients(target, project, target.author) recipients = build_recipients(target, project, target.author)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id) mailer.send(method, recipient.id, target.id).deliver_later
end end
end end
...@@ -347,7 +371,7 @@ class NotificationService ...@@ -347,7 +371,7 @@ class NotificationService
recipients = build_recipients(target, project, current_user) recipients = build_recipients(target, project, current_user)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, current_user.id) mailer.send(method, recipient.id, target.id, current_user.id).deliver
end end
end end
...@@ -358,7 +382,13 @@ class NotificationService ...@@ -358,7 +382,13 @@ class NotificationService
recipients = build_recipients(target, project, current_user, [previous_assignee]) recipients = build_recipients(target, project, current_user, [previous_assignee])
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, previous_assignee_id, current_user.id) mailer.send(
method,
recipient.id,
target.id,
previous_assignee_id,
current_user.id
).deliver_later
end end
end end
...@@ -366,7 +396,7 @@ class NotificationService ...@@ -366,7 +396,7 @@ class NotificationService
recipients = build_recipients(target, project, current_user) recipients = build_recipients(target, project, current_user)
recipients.each do |recipient| recipients.each do |recipient|
mailer.send(method, recipient.id, target.id, status, current_user.id) mailer.send(method, recipient.id, target.id, status, current_user.id).deliver
end end
end end
...@@ -388,7 +418,7 @@ class NotificationService ...@@ -388,7 +418,7 @@ class NotificationService
end end
def mailer def mailer
Notify.delay Notify
end end
def previous_record(object, attribute) def previous_record(object, attribute)
......
...@@ -46,6 +46,6 @@ class EmailReceiverWorker ...@@ -46,6 +46,6 @@ class EmailReceiverWorker
return return
end end
EmailRejectionMailer.delay.rejection(reason, raw, can_retry) EmailRejectionMailer.deliver_later.rejection(reason, raw, can_retry)
end end
end end
...@@ -99,6 +99,10 @@ module Gitlab ...@@ -99,6 +99,10 @@ module Gitlab
redis_config_hash[:expires_in] = 2.weeks # Cache should not grow forever redis_config_hash[:expires_in] = 2.weeks # Cache should not grow forever
config.cache_store = :redis_store, redis_config_hash config.cache_store = :redis_store, redis_config_hash
config.active_record.raise_in_transactional_callbacks = true
config.active_job.queue_adapter = :sidekiq
# This is needed for gitlab-shell # This is needed for gitlab-shell
ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH'] ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH']
end end
......
...@@ -9,7 +9,7 @@ Rails.application.configure do ...@@ -9,7 +9,7 @@ Rails.application.configure do
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this) # Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false config.serve_static_files = false
# Compress JavaScripts and CSS. # Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier config.assets.js_compressor = :uglifier
......
...@@ -8,7 +8,7 @@ Rails.application.configure do ...@@ -8,7 +8,7 @@ Rails.application.configure do
config.cache_classes = false config.cache_classes = false
# Configure static asset server for tests with Cache-Control for performance # Configure static asset server for tests with Cache-Control for performance
config.serve_static_assets = true config.serve_static_files = true
config.static_cache_control = "public, max-age=3600" config.static_cache_control = "public, max-age=3600"
# Show full error reports and disable caching # Show full error reports and disable caching
......
app = Rails.application app = Rails.application
if app.config.serve_static_assets if app.config.serve_static_files
# The `ActionDispatch::Static` middleware intercepts requests for static files # The `ActionDispatch::Static` middleware intercepts requests for static files
# by checking if they exist in the `/public` directory. # by checking if they exist in the `/public` directory.
# We're replacing it with our `Gitlab::Middleware::Static` that does the same, # We're replacing it with our `Gitlab::Middleware::Static` that does the same,
......
...@@ -60,8 +60,7 @@ module Gitlab ...@@ -60,8 +60,7 @@ module Gitlab
def url_for_label(project, label) def url_for_label(project, label)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Application.routes.url_helpers
h.namespace_project_issues_path(project.namespace, project, h.namespace_project_issues_path(project.namespace, project,
label_name: label.name, label_name: label.name)
only_path: context[:only_path])
end end
def render_colored_label(label) def render_colored_label(label)
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
def self.mute_mailer def self.mute_mailer
code = <<-eos code = <<-eos
def Notify.delay def Notify.deliver_later
self self
end end
eos eos
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment