2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-07-02 07:46:28 +08:00
|
|
|
module Jobs
|
|
|
|
|
2019-10-02 12:01:53 +08:00
|
|
|
class BadgeGrant < ::Jobs::Scheduled
|
2014-07-11 12:17:01 +08:00
|
|
|
def self.run
|
|
|
|
self.new.execute(nil)
|
|
|
|
end
|
|
|
|
|
2014-07-02 07:46:28 +08:00
|
|
|
every 1.day
|
|
|
|
|
|
|
|
def execute(args)
|
2014-09-03 04:12:27 +08:00
|
|
|
return unless SiteSetting.enable_badges
|
2014-10-08 07:26:18 +08:00
|
|
|
|
2016-01-19 04:41:12 +08:00
|
|
|
Badge.enabled.find_each do |b|
|
2015-03-29 09:36:05 +08:00
|
|
|
begin
|
|
|
|
BadgeGranter.backfill(b)
|
|
|
|
rescue => ex
|
|
|
|
# TODO - expose errors in UI
|
2017-07-28 09:20:09 +08:00
|
|
|
Discourse.handle_job_exception(ex, error_context({}, code_desc: 'Exception granting badges', extra: { badge_id: b.id }))
|
2015-03-29 09:36:05 +08:00
|
|
|
end
|
2014-07-03 15:29:44 +08:00
|
|
|
end
|
2014-10-08 07:26:18 +08:00
|
|
|
|
|
|
|
BadgeGranter.revoke_ungranted_titles!
|
2014-07-02 07:46:28 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|