Class: EventJob

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, ActionView::Helpers::DateHelper, Hydra::AccessControlsEnforcement, SufiaHelper
Defined in:
app/jobs/event_job.rb

Overview

A generic job for sending events to a user and their followers.

This class does not implement a usable action, so it must be implemented in a child class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sufia::SufiaHelperBehavior

#current_search_parameters, #display_user_name, #error_messages_for, #has_collection_search_parameters?, #iconify_auto_link, #iconify_link, #is_url?, #link_back_to_dashboard, #link_to_dashboard_query, #link_to_facet, #link_to_facet_list, #link_to_field, #link_to_profile, #link_to_telephone, #linkify_chat_id, #number_of_deposits, #orcid_label, #render_visibility_label, #render_visibility_link, #search_form_action, #show_transfer_request_title, #sufia_thumbnail_tag, #user_display_name_and_key, #zotero_label, #zotero_profile_url

Methods included from Sufia::BlacklightOverride

#render_bookmarks_control?, #render_constraints_query, #url_for_document

Constructor Details

#initialize(depositor_id) ⇒ EventJob

Returns a new instance of EventJob.

Parameters:

  • the

    id of the user to create the event for



22
23
24
# File 'app/jobs/event_job.rb', line 22

def initialize(depositor_id)
  @depositor_id = depositor_id
end

Instance Attribute Details

#depositor_idString

the user the event is specified for

Returns:

  • (String)

    the current value of depositor_id



7
8
9
# File 'app/jobs/event_job.rb', line 7

def depositor_id
  @depositor_id
end

Instance Method Details

#actionObject

This method is abstract.

override to provide your specific action for the event you are logging

Raises:

  • (NotImplementedError)


37
38
39
# File 'app/jobs/event_job.rb', line 37

def action
  raise(NotImplementedError, "#action should be implemented by an child class of EventJob")
end

#depositorObject

the user that will be the subject of the event



47
48
49
# File 'app/jobs/event_job.rb', line 47

def depositor
  @depositor ||= User.find_by_user_key(depositor_id)
end

#eventObject

create an event with an action and a timestamp for the user



42
43
44
# File 'app/jobs/event_job.rb', line 42

def event
  @event ||= depositor.create_event(action, Time.now.to_i)
end

#log_to_followersObject

log the event to the users followers



57
58
59
60
61
# File 'app/jobs/event_job.rb', line 57

def log_to_followers
  depositor.followers.each do |follower|
    follower.log_event(event)
  end
end

#log_user_eventObject

log the event to the users event stream



52
53
54
# File 'app/jobs/event_job.rb', line 52

def log_user_event
  depositor.log_event(event)
end

#queue_nameObject

queue to run the job on



15
16
17
# File 'app/jobs/event_job.rb', line 15

def queue_name
  :event
end

#runObject

Method used to cause the event to be created



27
28
29
30
31
32
33
# File 'app/jobs/event_job.rb', line 27

def run
  # Log the event to the depositor's profile stream
  log_user_event

  # Fan out the event to all followers who have access
  log_to_followers
end