Commit c098042d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '289856-immediately-calculate-snapshot' into 'master'

Resolve "[DevOps Adoption] Immediately process data for new segments"

See merge request gitlab-org/gitlab!50619
parents ae6ecae9 934bca8c
......@@ -20,6 +20,8 @@ module Analytics
segment.assign_attributes(attributes)
if segment.save
Analytics::DevopsAdoption::CreateSnapshotWorker.perform_async(segment.id, nil)
ServiceResponse.success(payload: response_payload)
else
ServiceResponse.error(message: 'Validation error', payload: response_payload)
......
---
title: Immediately calculate devops adoption data after segment creation
merge_request: 50619
author:
type: changed
# frozen_string_literal: true
Gitlab::Seeder.quiet do
admin = User.where(admin: true).first
if admin.nil?
puts "No admin user present"
next
end
groups = Group.take(5)
next if groups.empty?
......@@ -16,10 +9,10 @@ Gitlab::Seeder.quiet do
segment_groups_2 = groups.sample(3)
ActiveRecord::Base.transaction do
segment_1 = Analytics::DevopsAdoption::Segments::CreateService.new(params: { name: 'Segment 1', groups: segment_groups_1 }, current_user: admin).execute
segment_2 = Analytics::DevopsAdoption::Segments::CreateService.new(params: { name: 'Segment 2', groups: segment_groups_2 }, current_user: admin).execute
segments = [segment_1.payload[:segment], segment_2.payload[:segment]]
segments = [
Analytics::DevopsAdoption::Segment.create(name: 'Segment 1', groups: segment_groups_1),
Analytics::DevopsAdoption::Segment.create(name: 'Segment 2', groups: segment_groups_2)
]
if segments.any?(&:invalid?)
puts "Error creating segments"
......@@ -50,7 +43,7 @@ Gitlab::Seeder.quiet do
Analytics::DevopsAdoption::Snapshots::CreateService.new(params: calculated_data).execute
end
end
end
print '.'
print '.'
end
end
......@@ -23,6 +23,14 @@ RSpec.describe Analytics::DevopsAdoption::Segments::CreateService do
expect(segment.groups).to eq([group])
end
it 'schedules for snapshot creation' do
allow(Analytics::DevopsAdoption::CreateSnapshotWorker).to receive(:perform_async).and_call_original
subject
expect(Analytics::DevopsAdoption::CreateSnapshotWorker).to have_received(:perform_async).with(Analytics::DevopsAdoption::Segment.last.id, nil)
end
context 'when user is not an admin' do
let(:user) { build(:user) }
......
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