Method: ActivityNotification::NotificationApi.notify_later

Defined in:
lib/activity_notification/apis/notification_api.rb

.notify_later(target_type, notifiable, options = {}) ⇒ Array<Notificaion>

Generates notifications to configured targets with notifiable model later by ActiveJob queue.

Examples:

Use with target_type as Symbol

ActivityNotification::Notification.notify_later :users, @comment

Use with target_type as String

ActivityNotification::Notification.notify_later 'User', @comment

Use with target_type as Class

ActivityNotification::Notification.notify_later User, @comment

Use with options

ActivityNotification::Notification.notify_later :users, @comment, key: 'custom.comment', group: @comment.article
ActivityNotification::Notification.notify_later :users, @comment, parameters: { reply_to: @comment.reply_to }, send_later: false

Parameters:

  • target_type (Symbol, String, Class)

    Type of target

  • notifiable (Object)

    Notifiable instance

  • options (Hash) (defaults to: {})

    Options for notifications

Options Hash (options):

  • :key (String) — default: notifiable.default_notification_key

    Key of the notification

  • :group (Object) — default: nil

    Group unit of the notifications

  • :group_expiry_delay (ActiveSupport::Duration) — default: nil

    Expiry period of a notification group

  • :notifier (Object) — default: nil

    Notifier of the notifications

  • :parameters (Hash) — default: {}

    Additional parameters of the notifications

  • :send_email (Boolean) — default: true

    Whether it sends notification email

  • :send_later (Boolean) — default: true

    Whether it sends notification email asynchronously

  • :publish_optional_targets (Boolean) — default: true

    Whether it publishes notification to optional targets

  • :pass_full_options (Boolean) — default: false

    Whether it passes full options to notifiable.notification_targets, not a key only

  • :optional_targets (Hash<String, Hash>) — default: {}

    Options for optional targets, keys are optional target name (:amazon_sns or :slack etc) and values are options

Returns:

  • (Array<Notificaion>)

    Array of generated notifications



264
265
266
267
268
# File 'lib/activity_notification/apis/notification_api.rb', line 264

def notify_later(target_type, notifiable, options = {})
  target_type = target_type.to_s if target_type.is_a? Symbol
  options.delete(:notify_later)
  ActivityNotification::NotifyJob.perform_later(target_type, notifiable, options)
end