Change service to be a worker, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6342#note_16118195
This commit is contained in:
parent
9622ef64e4
commit
eeeb96c9d0
6 changed files with 19 additions and 21 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
9
app/workers/send_pipeline_notification_worker.rb
Normal file
9
app/workers/send_pipeline_notification_worker.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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)
|
Loading…
Reference in a new issue