Skip to content

Commit

Permalink
Adjust the rollout tasks
Browse files Browse the repository at this point in the history
Most of the rollout tasks like "all_on" or "from_beta" excluded the staff
users. Semantically speaking it was confusing. As we no longer need that
restriction, the staff are not excluded anymore.

We also add tasks to move the anonymous user (_nobody_) into or out of the
rollout program. Something that is usually needed at the beginning or end of
the rollout process.
  • Loading branch information
saraycp committed Jan 18, 2021
1 parent d749e0a commit 5c2d6f8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
34 changes: 22 additions & 12 deletions src/api/lib/tasks/rollout.rake
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
# rubocop:disable Rails/SkipsModelValidations

# Follow the recommendations for the rollout in:
# https://github.com/openSUSE/open-build-service/wiki/Feature-Toggles#steps-for-rolling-out

namespace :rollout do
desc 'Move all the users to rollout program'
task all_on: :environment do
User.all_without_nobody
.not_staff
.where(in_rollout: false).in_batches.update_all(in_rollout: true)
end

desc 'Move all the users out of the rollout program'
task all_off: :environment do
User.all_without_nobody
.not_staff
.where(in_rollout: true).in_batches.update_all(in_rollout: false)
end

desc 'Move the users already in beta to rollout program'
task from_beta: :environment do
User.not_staff
.where(in_beta: true, in_rollout: false).in_batches.update_all(in_rollout: true)
end

desc 'Move the members of groups to rollout program'
task from_groups: :environment do
User.not_staff
.where(in_rollout: false).joins(:groups_users).distinct.in_batches.update_all(in_rollout: true)
User.where(in_beta: true, in_rollout: false).in_batches.update_all(in_rollout: true)
end

desc 'Move the users with recent activity to rollout program'
task recently_logged_users: :environment do
User.all_without_nobody
.not_staff
.where(in_rollout: false, last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today)
.in_batches.update_all(in_rollout: true)
end

desc 'Move the users without recent activity to rollout program'
task non_recently_logged_users: :environment do
User.all_without_nobody
.not_staff
.where.not(in_rollout: true).where.not(last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today)
.in_batches.update_all(in_rollout: true)
end

desc 'Move the members of groups to rollout program'
task from_groups: :environment do
User.where(in_rollout: false).joins(:groups_users).distinct.in_batches.update_all(in_rollout: true)
end

desc 'Move Staff users to rollout program'
task staff_on: :environment do
User.staff
Expand All @@ -53,5 +51,17 @@ namespace :rollout do
User.staff
.where(in_rollout: true).in_batches.update_all(in_rollout: false)
end

desc 'Move the anonymous user to the rollout program'
task anonymous_on: :environment do
user = User.find_by(login: '_nobody_', in_rollout: false)
user&.update_column(:in_rollout, true)
end

desc 'Move the anonymous user out of the rollout program'
task anonymous_off: :environment do
user = User.find_by(login: '_nobody_', in_rollout: true)
user&.update_column(:in_rollout, false)
end
end
# rubocop:enable Rails/SkipsModelValidations
42 changes: 31 additions & 11 deletions src/api/spec/lib/tasks/rollout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@
it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) }
end

describe 'from_groups' do
let(:task) { 'rollout:from_groups' }
let(:users) { User.joins(:groups_users).distinct }

it 'will move all the users from groups to Rollout Program' do
expect { rake_task.invoke }.to change(users.where(in_rollout: true), :count).from(1).to(2)
end

it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) }
end

describe 'recently_logged_users' do
let(:task) { 'rollout:recently_logged_users' }
let(:users) { User.where(last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today) }
Expand All @@ -85,6 +74,17 @@
it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) }
end

describe 'from_groups' do
let(:task) { 'rollout:from_groups' }
let(:users) { User.joins(:groups_users).distinct }

it 'will move all the users from groups to Rollout Program' do
expect { rake_task.invoke }.to change(users.where(in_rollout: true), :count).from(1).to(2)
end

it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) }
end

context 'with Staff users' do
let!(:staff_user_1) { create(:staff_user, in_rollout: false) }
let!(:staff_user_2) { create(:staff_user, in_rollout: false) }
Expand All @@ -111,4 +111,24 @@
it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(4).to(3) }
end
end

context 'with anonymous user' do
describe 'anonymous_on' do
let!(:anonymous_user) { create(:user_nobody, in_rollout: false) }
let(:task) { 'rollout:anonymous_on' }

it 'will move the anonymous user to Rollout Program' do
expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4)
end
end

describe 'anonymous_off' do
let!(:anonymous_user) { create(:user_nobody, in_rollout: true) }
let(:task) { 'rollout:anonymous_off' }

it 'will move anonymous user out of Rollout Program' do
expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(4).to(3)
end
end
end
end

0 comments on commit 5c2d6f8

Please sign in to comment.