Class: Jobs::CheckNewFeatures

Inherits:
Scheduled show all
Defined in:
app/jobs/scheduled/check_new_features.rb

Instance Method Summary collapse

Methods inherited from Scheduled

#perform

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/jobs/scheduled/check_new_features.rb', line 7

def execute(args)
  admin_ids = User.human_users.where(admin: true).pluck(:id)

  prev_most_recent = DiscourseUpdates.new_features&.first
  if prev_most_recent
    admin_ids.each do |admin_id|
      if DiscourseUpdates.get_last_viewed_feature_date(admin_id).blank?
        DiscourseUpdates.bump_last_viewed_feature_date(admin_id, prev_most_recent["created_at"])
      end
    end
  end

  # this memoization may seem pointless, but it actually avoids us hitting
  # Meta repeatedly and getting rate-limited when this job is ran on a
  # multisite cluster.
  # in multisite, the `execute` method (of the same instance) is called for
  # every site in the cluster.
  @new_features_json ||= DiscourseUpdates.new_features_payload
  DiscourseUpdates.update_new_features(@new_features_json)

  new_most_recent = DiscourseUpdates.new_features&.first
  if new_most_recent
    most_recent_feature_date = Time.zone.parse(new_most_recent["created_at"])
    admin_ids.each do |admin_id|
      admin_last_viewed_feature_date = DiscourseUpdates.get_last_viewed_feature_date(admin_id)
      if admin_last_viewed_feature_date.blank? ||
           admin_last_viewed_feature_date < most_recent_feature_date
        Notification.consolidate_or_create!(
          user_id: admin_id,
          notification_type: Notification.types[:new_features],
          data: {
          },
        )
        DiscourseUpdates.bump_last_viewed_feature_date(admin_id, new_most_recent["created_at"])
      end
    end
  end
end