Commit eeeb96c9 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 9622ef64
...@@ -83,8 +83,8 @@ module Ci ...@@ -83,8 +83,8 @@ module Ci
end end
end end
after_transition any => [:success, :failed] do |pipeline, transition| after_transition any => [:success, :failed] do |pipeline|
SendPipelineNotificationService.new(pipeline).execute SendPipelineNotificationWorker.perform_async(pipeline.id)
end end
end end
......
...@@ -31,8 +31,8 @@ class PipelinesEmailService < Service ...@@ -31,8 +31,8 @@ class PipelinesEmailService < Service
return unless all_recipients.any? return unless all_recipients.any?
pipeline = Ci::Pipeline.find(data[:object_attributes][:id]) pipeline_id = data[:object_attributes][:id]
Ci::SendPipelineNotificationService.new(pipeline).execute(all_recipients) SendPipelineNotificationWorker.perform_async(pipeline_id, all_recipients)
end end
def can_test? def can_test?
......
module Ci
class SendPipelineNotificationService < BaseService
attr_reader :pipeline
def initialize(new_pipeline)
@pipeline = new_pipeline
end
def execute(recipients = nil)
notification_service.pipeline_finished(pipeline, recipients)
end
end
end
class SendPipelineNotificationWorker
include Sidekiq::Worker
def perform(pipeline_id, recipients = nil)
pipeline = Ci::Pipeline.find(pipeline_id)
NotificationService.new.pipeline_finished(pipeline, recipients)
end
end
...@@ -537,9 +537,11 @@ describe Ci::Pipeline, models: true do ...@@ -537,9 +537,11 @@ describe Ci::Pipeline, models: true do
before do before do
reset_delivered_emails! reset_delivered_emails!
perform_enqueued_jobs do
pipeline.enqueue pipeline.enqueue
pipeline.run pipeline.run
end end
end
shared_examples 'sending a notification' do shared_examples 'sending a notification' do
it 'sends an email' do it 'sends an email' do
......
require 'spec_helper' require 'spec_helper'
describe Ci::SendPipelineNotificationService, services: true do describe SendPipelineNotificationWorker, services: true do
let(:pipeline) do let(:pipeline) do
create(:ci_pipeline, create(:ci_pipeline,
project: project, project: project,
...@@ -23,7 +23,7 @@ describe Ci::SendPipelineNotificationService, services: true do ...@@ -23,7 +23,7 @@ describe Ci::SendPipelineNotificationService, services: true do
shared_examples 'sending emails' do shared_examples 'sending emails' do
it 'sends emails' do it 'sends emails' do
perform_enqueued_jobs do perform_enqueued_jobs do
subject.execute subject.perform(pipeline.id)
end end
expected_receivers = [pusher, watcher].uniq.sort_by(&:email) expected_receivers = [pusher, watcher].uniq.sort_by(&:email)
......
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