discourse-subscriptions/app/jobs/grant_badge.rb

33 lines
776 B
Ruby
Raw Normal View History

2017-04-27 04:47:27 -04:00
module Jobs
class GrantBadge < ::Jobs::Scheduled
every 5.minutes
def execute(_args)
2017-04-27 06:26:36 -04:00
puts "===================== Running badge grant ========================"
puts user_queue
2017-04-27 05:10:00 -04:00
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
2017-04-27 04:47:27 -04:00
end
end
end