2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-07-01 19:46:28 -04:00
|
|
|
module Jobs
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class BadgeGrant < ::Jobs::Scheduled
|
2014-07-11 00:17:01 -04:00
|
|
|
def self.run
|
|
|
|
self.new.execute(nil)
|
|
|
|
end
|
|
|
|
|
2014-07-01 19:46:28 -04:00
|
|
|
every 1.day
|
|
|
|
|
|
|
|
def execute(args)
|
2014-09-02 16:12:27 -04:00
|
|
|
return unless SiteSetting.enable_badges
|
2014-10-07 19:26:18 -04:00
|
|
|
|
2016-01-18 15:41:12 -05:00
|
|
|
Badge.enabled.find_each do |b|
|
2015-03-28 21:36:05 -04:00
|
|
|
begin
|
|
|
|
BadgeGranter.backfill(b)
|
|
|
|
rescue => ex
|
|
|
|
# TODO - expose errors in UI
|
|
|
|
Discourse.handle_job_exception(ex, error_context({}, code_desc: 'Exception granting badges', extra: { badge_id: b.id }))
|
|
|
|
end
|
2014-07-03 03:29:44 -04:00
|
|
|
end
|
2014-10-07 19:26:18 -04:00
|
|
|
|
|
|
|
BadgeGranter.revoke_ungranted_titles!
|
2020-01-14 09:26:49 -05:00
|
|
|
UserBadge.ensure_consistency! # Badge granter sometimes uses raw SQL, so hooks do not run. Clean up data
|
2020-11-18 16:01:56 -05:00
|
|
|
UserStat.update_distinct_badge_count
|
2014-07-01 19:46:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|