Module: RailsOnboarding::BackgroundJobs

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_onboarding/background_jobs.rb

Overview

Background job support for queuing emails and notifications Compatible with ActiveJob, Sidekiq, Resque, and DelayedJob

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MAX_JOBS_PER_USER_PER_HOUR =

Throttling constants to prevent queue overflow

100
MAX_TOTAL_JOBS_PER_MINUTE =
1000

Instance Method Summary collapse

Instance Method Details

#queue_analytics_event(event_name, user, data = {}) ⇒ Object

Queue analytics events



69
70
71
72
73
74
# File 'lib/rails_onboarding/background_jobs.rb', line 69

def queue_analytics_event(event_name, user, data = {})
  return unless RailsOnboarding.active_job_available?
  return unless can_queue_job_for_user?(user)

  OnboardingAnalyticsJob.perform_later(event_name, user.id, data)
end

#queue_milestone_achievement(user, milestone_id) ⇒ Object

Queue milestone achievements



77
78
79
80
81
82
# File 'lib/rails_onboarding/background_jobs.rb', line 77

def queue_milestone_achievement(user, milestone_id)
  return unless RailsOnboarding.active_job_available?
  return unless can_queue_job_for_user?(user)

  MilestoneAchievementJob.perform_later(user.id, milestone_id)
end

#queue_onboarding_completion_email(user) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/rails_onboarding/background_jobs.rb', line 51

def queue_onboarding_completion_email(user)
  return unless RailsOnboarding.active_job_available?
  return unless background_jobs_enabled?(:emails)
  return unless can_queue_job_for_user?(user)

  OnboardingMailerJob.perform_later(user.id, :completion)
end

#queue_onboarding_notification(user, notification_type, data = {}) ⇒ Object

Queue notifications



60
61
62
63
64
65
66
# File 'lib/rails_onboarding/background_jobs.rb', line 60

def queue_onboarding_notification(user, notification_type, data = {})
  return unless RailsOnboarding.active_job_available?
  return unless background_jobs_enabled?(:notifications)
  return unless can_queue_job_for_user?(user)

  OnboardingNotificationJob.perform_later(user.id, notification_type, data)
end

#queue_onboarding_reminder_email(user) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rails_onboarding/background_jobs.rb', line 43

def queue_onboarding_reminder_email(user)
  return unless RailsOnboarding.active_job_available?
  return unless background_jobs_enabled?(:emails)
  return unless can_queue_job_for_user?(user)

  OnboardingMailerJob.set(wait: 1.day).perform_later(user.id, :reminder)
end

#queue_onboarding_welcome_email(user) ⇒ Object

Queue onboarding emails



35
36
37
38
39
40
41
# File 'lib/rails_onboarding/background_jobs.rb', line 35

def queue_onboarding_welcome_email(user)
  return unless RailsOnboarding.active_job_available?
  return unless background_jobs_enabled?(:emails)
  return unless can_queue_job_for_user?(user)

  OnboardingMailerJob.perform_later(user.id, :welcome)
end