Class: Thredded::ActivityUpdaterJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/thredded/activity_updater_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(user_id, messageboard_id) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/thredded/activity_updater_job.rb', line 7

def perform(user_id, messageboard_id)
  now = Time.current

  begin
    user_detail = Thredded::UserDetail.find_or_initialize_by(user_id: user_id)
    user_detail.update!(last_seen_at: now)
  rescue ActiveRecord::RecordNotUnique
    # The record has been created from another connection, retry to find it.
    retry
  end

  begin
    Thredded::MessageboardUser
      .find_or_initialize_by(
        thredded_messageboard_id: messageboard_id,
        thredded_user_detail_id: user_detail.id
      )
      .update!(last_seen_at: now)
  rescue ActiveRecord::RecordNotUnique
    # The record has been created from another connection, retry to find it.
    retry
  end
end