Read about our upcoming Code of Conduct on this issue

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

Migrate mailers to ActiveJob

parent 4b88ddcb310a
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)
......
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 @@ def create
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 @@ def update_project
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 @@ def reopen_issue(issue, current_user)
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 @@ def new_note(note)
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 @@ def project_was_moved(project, old_path_with_namespace)
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 @@ def new_resource_email(target, project, method)
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 @@ def close_resource_email(target, project, current_user, method)
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 @@ def reassign_resource_email(target, project, current_user, method)
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 @@ def reopen_resource_email(target, project, current_user, method, status)
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 @@ def build_recipients(target, project, current_user, extra_recipients = nil)
end
def mailer
Notify.delay
Notify
end
def previous_record(object, attribute)
......
......@@ -46,6 +46,6 @@ def handle_failure(raw, e)
return
end
EmailRejectionMailer.delay.rejection(reason, raw, can_retry)
EmailRejectionMailer.deliver_later.rejection(reason, raw, can_retry)
end
end
......@@ -99,6 +99,10 @@ class Application < Rails::Application
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 @@
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 @@
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
......
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 @@ def label_link_filter(text)
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 @@ def self.by_user(user)
def self.mute_mailer
code = <<-eos
def Notify.delay
def Notify.deliver_later
self
end
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