Commit 934bca8c authored by Pavel Shutsin's avatar Pavel Shutsin

Schedule immediate snapshot calculation

So user sees snapshot data for
current month immediately after creation
parent aaeddaa7
...@@ -20,6 +20,8 @@ module Analytics ...@@ -20,6 +20,8 @@ module Analytics
segment.assign_attributes(attributes) segment.assign_attributes(attributes)
if segment.save if segment.save
Analytics::DevopsAdoption::CreateSnapshotWorker.perform_async(segment.id, nil)
ServiceResponse.success(payload: response_payload) ServiceResponse.success(payload: response_payload)
else else
ServiceResponse.error(message: 'Validation error', payload: response_payload) 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 # frozen_string_literal: true
Gitlab::Seeder.quiet do Gitlab::Seeder.quiet do
admin = User.where(admin: true).first
if admin.nil?
puts "No admin user present"
next
end
groups = Group.take(5) groups = Group.take(5)
next if groups.empty? next if groups.empty?
...@@ -16,10 +9,10 @@ Gitlab::Seeder.quiet do ...@@ -16,10 +9,10 @@ Gitlab::Seeder.quiet do
segment_groups_2 = groups.sample(3) segment_groups_2 = groups.sample(3)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
segment_1 = Analytics::DevopsAdoption::Segments::CreateService.new(params: { name: 'Segment 1', groups: segment_groups_1 }, current_user: admin).execute segments = [
segment_2 = Analytics::DevopsAdoption::Segments::CreateService.new(params: { name: 'Segment 2', groups: segment_groups_2 }, current_user: admin).execute Analytics::DevopsAdoption::Segment.create(name: 'Segment 1', groups: segment_groups_1),
Analytics::DevopsAdoption::Segment.create(name: 'Segment 2', groups: segment_groups_2)
segments = [segment_1.payload[:segment], segment_2.payload[:segment]] ]
if segments.any?(&:invalid?) if segments.any?(&:invalid?)
puts "Error creating segments" puts "Error creating segments"
...@@ -50,7 +43,7 @@ Gitlab::Seeder.quiet do ...@@ -50,7 +43,7 @@ Gitlab::Seeder.quiet do
Analytics::DevopsAdoption::Snapshots::CreateService.new(params: calculated_data).execute Analytics::DevopsAdoption::Snapshots::CreateService.new(params: calculated_data).execute
end end
end end
end
print '.' print '.'
end
end end
...@@ -23,6 +23,14 @@ RSpec.describe Analytics::DevopsAdoption::Segments::CreateService do ...@@ -23,6 +23,14 @@ RSpec.describe Analytics::DevopsAdoption::Segments::CreateService do
expect(segment.groups).to eq([group]) expect(segment.groups).to eq([group])
end 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 context 'when user is not an admin' do
let(:user) { build(:user) } 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