diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 61bb89a0a23db360edaee96413e0f05b968cfe56..d534fdc05607a0b003c3073921cfd647f685cebf 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -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 diff --git a/app/models/project_services/pipelines_email_service.rb b/app/models/project_services/pipelines_email_service.rb index ec27aa88f16c16aad3a9016de573f9cf037bd635..4cebb9e7f9312d5ff488158fd136b9adaa9f7817 100644 --- a/app/models/project_services/pipelines_email_service.rb +++ b/app/models/project_services/pipelines_email_service.rb @@ -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? diff --git a/app/services/ci/send_pipeline_notification_service.rb b/app/services/ci/send_pipeline_notification_service.rb deleted file mode 100644 index d330fa1a73c2324634d8de82cbbd443c7f4c222e..0000000000000000000000000000000000000000 --- a/app/services/ci/send_pipeline_notification_service.rb +++ /dev/null @@ -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 diff --git a/app/workers/send_pipeline_notification_worker.rb b/app/workers/send_pipeline_notification_worker.rb new file mode 100644 index 0000000000000000000000000000000000000000..d4837d815a5a8008772d0c5cf334f5299aaf642a --- /dev/null +++ b/app/workers/send_pipeline_notification_worker.rb @@ -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 diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 787042cf05573d473de053f145fd8ea3b4c8e20c..6ea712ae1b3b67b65dde278d35819d26ae2598ef 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -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 diff --git a/spec/services/ci/send_pipeline_notification_service_spec.rb b/spec/workers/send_pipeline_notification_worker_spec.rb similarity index 96% rename from spec/services/ci/send_pipeline_notification_service_spec.rb rename to spec/workers/send_pipeline_notification_worker_spec.rb index 110e16410c5729a002246c19c180b5b4d78f7d3c..0670d67501a2d5552dc72641028f183661ed3b2e 100644 --- a/spec/services/ci/send_pipeline_notification_service_spec.rb +++ b/spec/workers/send_pipeline_notification_worker_spec.rb @@ -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)