remove old jobs for awards

This commit is contained in:
Rimian Perkins 2017-05-12 10:46:48 +10:00
parent c12cc3246a
commit b663bf5447
5 changed files with 0 additions and 105 deletions

View File

@ -1,32 +0,0 @@
module Jobs
class AwardGroup < ::Jobs::Scheduled
every 1.minutes
def execute(_args)
puts "===================== Running add to group ========================"
puts user_queue
user_queue.each do |email|
user = User.find_by_email(email)
next if user.nil?
puts "Added user #{user.email} to #{group_name}"
DiscourseDonations::Rewards.new(user).add_to_group(group_name)
end
user_queue_reset
end
private
def user_queue
PluginStore.get('discourse-donations', 'group:add') || []
end
def user_queue_reset
PluginStore.set('discourse-donations', 'group:add', [])
end
def group_name
SiteSetting.discourse_donations_reward_group_name
end
end
end

View File

@ -1,32 +0,0 @@
module Jobs
class GrantBadge < ::Jobs::Scheduled
every 5.minutes
def execute(_args)
puts "===================== Running badge grant ========================"
puts user_queue
user_queue.each do |email|
user = User.find_by_email(email)
next if user.nil?
puts "Granted user #{user.email} with badge: #{badge_name}"
DiscourseDonations::Rewards.new(user).grant_badge(badge_name)
end
user_queue_reset
end
private
def user_queue
PluginStore.get('discourse-donations', 'badge:grant') || []
end
def user_queue_reset
PluginStore.set('discourse-donations', 'badge:grant', [])
end
def badge_name
SiteSetting.discourse_donations_reward_badge_name
end
end
end

View File

@ -1,4 +1 @@
load File.expand_path('../award_group.rb', __FILE__)
load File.expand_path('../grant_badge.rb', __FILE__)
load File.expand_path('../regular/donation_user.rb', __FILE__)

View File

@ -1,19 +0,0 @@
require 'rails_helper'
RSpec.describe Jobs::AwardGroup, type: :job do
let(:users) { [Fabricate(:user), Fabricate(:user)] }
let(:grp) { Fabricate(:group, name: 'chimichanga') }
before do
SiteSetting.stubs(:discourse_donations_reward_group_name).returns(grp.name)
PluginStore.set('discourse-donations', 'group:add', [users.first.email, users.last.email])
end
it 'adds the users to the group' do
Jobs::AwardGroup.new.execute(nil)
aggregate_failures do
expect(users.first.groups).to include(grp)
expect(users.last.groups).to include(grp)
end
end
end

View File

@ -1,19 +0,0 @@
require 'rails_helper'
RSpec.describe Jobs::GrantBadge, type: :job do
let(:users) { [Fabricate(:user), Fabricate(:user)] }
let(:badge) { Fabricate(:badge, name: 'el-grande') }
before do
SiteSetting.stubs(:discourse_donations_reward_badge_name).returns(badge.name)
PluginStore.set('discourse-donations', 'badge:grant', [users.first.email, users.last.email])
end
it 'grants all the users the badge' do
Jobs::GrantBadge.new.execute(nil)
aggregate_failures do
expect(users.first.badges).to include(badge)
expect(users.last.badges).to include(badge)
end
end
end