Migrate mailers to ActiveJob
This commit is contained in:
parent
3e0fe27627
commit
7f214cee74
14 changed files with 67 additions and 36 deletions
1
Gemfile
1
Gemfile
|
@ -1,6 +1,7 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem 'rails', '4.2.4'
|
||||
gem 'rails-deprecated_sanitizer', '~> 1.0.3'
|
||||
|
||||
# Responders respond_to and respond_with
|
||||
gem 'responders', '~> 2.0'
|
||||
|
|
|
@ -930,6 +930,7 @@ DEPENDENCIES
|
|||
rack-cors (~> 0.4.0)
|
||||
rack-oauth2 (~> 1.2.1)
|
||||
rails (= 4.2.4)
|
||||
rails-deprecated_sanitizer (~> 1.0.3)
|
||||
raphael-rails (~> 2.1.2)
|
||||
rblineprof
|
||||
rdoc (~> 3.6)
|
||||
|
|
2
Procfile
2
Procfile
|
@ -1,3 +1,3 @@
|
|||
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
|
||||
|
|
|
@ -10,7 +10,7 @@ class AbuseReportsController < ApplicationController
|
|||
|
||||
if @abuse_report.save
|
||||
if current_application_settings.admin_notification_email.present?
|
||||
AbuseReportMailer.delay.notify(@abuse_report.id)
|
||||
AbuseReportMailer.deliver_later.notify(@abuse_report.id)
|
||||
end
|
||||
|
||||
message = "Thank you for your report. A GitLab administrator will look into it shortly."
|
||||
|
|
|
@ -8,10 +8,6 @@ class BaseMailer < ActionMailer::Base
|
|||
default from: Proc.new { default_sender_address.format }
|
||||
default reply_to: Proc.new { default_reply_to_address.format }
|
||||
|
||||
def self.delay
|
||||
delay_for(2.seconds)
|
||||
end
|
||||
|
||||
def can?
|
||||
Ability.abilities.allowed?(current_user, action, subject)
|
||||
end
|
||||
|
|
|
@ -78,7 +78,7 @@ module Ci
|
|||
end
|
||||
|
||||
def mailer
|
||||
Ci::Notify.delay
|
||||
Ci::Notify.deliver_later
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,14 +13,14 @@ class NotificationService
|
|||
# even if user disabled notifications
|
||||
def new_key(key)
|
||||
if key.user
|
||||
mailer.new_ssh_key_email(key.id)
|
||||
mailer.new_ssh_key_email(key.id).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
# Always notify user about email added to profile
|
||||
def new_email(email)
|
||||
if email.user
|
||||
mailer.new_email_email(email.id)
|
||||
mailer.new_email_email(email.id).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -79,17 +79,27 @@ class NotificationService
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
# Notify new user with email after creation
|
||||
def new_user(user, token = nil)
|
||||
# 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
|
||||
|
||||
# Notify users on new note in system
|
||||
|
@ -140,48 +150,58 @@ class NotificationService
|
|||
notify_method = "note_#{note.noteable_type.underscore}_email".to_sym
|
||||
|
||||
recipients.each do |recipient|
|
||||
mailer.send(notify_method, recipient.id, note.id)
|
||||
mailer.send(notify_method, recipient.id, note.id).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def project_was_moved(project, old_path_with_namespace)
|
||||
|
@ -189,7 +209,11 @@ class NotificationService
|
|||
recipients = reject_muted_users(recipients, project)
|
||||
|
||||
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
|
||||
|
||||
|
@ -339,7 +363,7 @@ class NotificationService
|
|||
recipients = build_recipients(target, project, target.author)
|
||||
|
||||
recipients.each do |recipient|
|
||||
mailer.send(method, recipient.id, target.id)
|
||||
mailer.send(method, recipient.id, target.id).deliver_later
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -347,7 +371,7 @@ class NotificationService
|
|||
recipients = build_recipients(target, project, current_user)
|
||||
|
||||
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
|
||||
|
||||
|
@ -358,7 +382,13 @@ class NotificationService
|
|||
recipients = build_recipients(target, project, current_user, [previous_assignee])
|
||||
|
||||
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
|
||||
|
||||
|
@ -366,7 +396,7 @@ class NotificationService
|
|||
recipients = build_recipients(target, project, current_user)
|
||||
|
||||
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
|
||||
|
||||
|
@ -388,7 +418,7 @@ class NotificationService
|
|||
end
|
||||
|
||||
def mailer
|
||||
Notify.delay
|
||||
Notify
|
||||
end
|
||||
|
||||
def previous_record(object, attribute)
|
||||
|
|
|
@ -46,6 +46,6 @@ class EmailReceiverWorker
|
|||
return
|
||||
end
|
||||
|
||||
EmailRejectionMailer.delay.rejection(reason, raw, can_retry)
|
||||
EmailRejectionMailer.deliver_later.rejection(reason, raw, can_retry)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -99,6 +99,10 @@ module Gitlab
|
|||
redis_config_hash[:expires_in] = 2.weeks # Cache should not grow forever
|
||||
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
|
||||
ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH']
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ Rails.application.configure do
|
|||
config.action_controller.perform_caching = true
|
||||
|
||||
# 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.
|
||||
config.assets.js_compressor = :uglifier
|
||||
|
|
|
@ -8,7 +8,7 @@ Rails.application.configure do
|
|||
config.cache_classes = false
|
||||
|
||||
# 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"
|
||||
|
||||
# Show full error reports and disable caching
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
app = Rails.application
|
||||
|
||||
if app.config.serve_static_assets
|
||||
if app.config.serve_static_files
|
||||
# The `ActionDispatch::Static` middleware intercepts requests for static files
|
||||
# by checking if they exist in the `/public` directory.
|
||||
# We're replacing it with our `Gitlab::Middleware::Static` that does the same,
|
||||
|
|
|
@ -60,8 +60,7 @@ module Gitlab
|
|||
def url_for_label(project, label)
|
||||
h = Gitlab::Application.routes.url_helpers
|
||||
h.namespace_project_issues_path(project.namespace, project,
|
||||
label_name: label.name,
|
||||
only_path: context[:only_path])
|
||||
label_name: label.name)
|
||||
end
|
||||
|
||||
def render_colored_label(label)
|
||||
|
|
|
@ -14,7 +14,7 @@ module Gitlab
|
|||
|
||||
def self.mute_mailer
|
||||
code = <<-eos
|
||||
def Notify.delay
|
||||
def Notify.deliver_later
|
||||
self
|
||||
end
|
||||
eos
|
||||
|
|
Loading…
Reference in a new issue