Change service to be a worker, feedback:

https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_16118195
This commit is contained in:
Lin Jen-Shin 2016-09-28 17:22:06 +08:00
parent 9622ef64e4
commit eeeb96c9d0
6 changed files with 19 additions and 21 deletions

View File

@ -83,8 +83,8 @@ module Ci
end
end
after_transition any => [:success, :failed] do |pipeline, transition|
SendPipelineNotificationService.new(pipeline).execute
after_transition any => [:success, :failed] do |pipeline|
SendPipelineNotificationWorker.perform_async(pipeline.id)
end
end

View File

@ -31,8 +31,8 @@ class PipelinesEmailService < Service
return unless all_recipients.any?
pipeline = Ci::Pipeline.find(data[:object_attributes][:id])
Ci::SendPipelineNotificationService.new(pipeline).execute(all_recipients)
pipeline_id = data[:object_attributes][:id]
SendPipelineNotificationWorker.perform_async(pipeline_id, all_recipients)
end
def can_test?

View File

@ -1,13 +0,0 @@
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

View File

@ -0,0 +1,9 @@
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

View File

@ -537,8 +537,10 @@ describe Ci::Pipeline, models: true do
before do
reset_delivered_emails!
pipeline.enqueue
pipeline.run
perform_enqueued_jobs do
pipeline.enqueue
pipeline.run
end
end
shared_examples 'sending a notification' do

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe Ci::SendPipelineNotificationService, services: true do
describe SendPipelineNotificationWorker, services: true do
let(:pipeline) do
create(:ci_pipeline,
project: project,
@ -23,7 +23,7 @@ describe Ci::SendPipelineNotificationService, services: true do
shared_examples 'sending emails' do
it 'sends emails' do
perform_enqueued_jobs do
subject.execute
subject.perform(pipeline.id)
end
expected_receivers = [pusher, watcher].uniq.sort_by(&:email)