Class: Namespaces::InProductMarketingEmailsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/namespaces/in_product_marketing_emails_service.rb

Constant Summary collapse

TRACKS =
{
  create: {
    interval_days: [1, 5, 10],
    completed_actions: [:created],
    incomplete_actions: [:git_write]
  },
  team_short: {
    interval_days: [1],
    completed_actions: [:git_write],
    incomplete_actions: [:user_added]
  },
  trial_short: {
    interval_days: [2],
    completed_actions: [:git_write],
    incomplete_actions: [:trial_started]
  },
  admin_verify: {
    interval_days: [3],
    completed_actions: [:git_write],
    incomplete_actions: [:pipeline_created]
  },
  verify: {
    interval_days: [4, 8, 13],
    completed_actions: [:git_write],
    incomplete_actions: [:pipeline_created]
  },
  trial: {
    interval_days: [1, 5, 10],
    completed_actions: [:git_write, :pipeline_created],
    incomplete_actions: [:trial_started]
  },
  team: {
    interval_days: [1, 5, 10],
    completed_actions: [:git_write, :pipeline_created, :trial_started],
    incomplete_actions: [:user_added]
  },
  experience: {
    interval_days: [30],
    completed_actions: [:created, :git_write],
    incomplete_actions: []
  }
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(track, interval) ⇒ InProductMarketingEmailsService

Returns a new instance of InProductMarketingEmailsService.


61
62
63
64
65
# File 'app/services/namespaces/in_product_marketing_emails_service.rb', line 61

def initialize(track, interval)
  @track = track
  @interval = interval
  @sent_email_records = ::Users::InProductMarketingEmailRecords.new
end

Class Method Details

.email_count_for_track(track) ⇒ Object


48
49
50
51
# File 'app/services/namespaces/in_product_marketing_emails_service.rb', line 48

def self.email_count_for_track(track)
  interval_days = TRACKS.dig(track.to_sym, :interval_days)
  interval_days&.count || 0
end

.send_for_all_tracks_and_intervalsObject


53
54
55
56
57
58
59
# File 'app/services/namespaces/in_product_marketing_emails_service.rb', line 53

def self.send_for_all_tracks_and_intervals
  TRACKS.each_key do |track|
    TRACKS[track][:interval_days].each do |interval|
      new(track, interval).execute
    end
  end
end

Instance Method Details

#executeObject

Raises:

  • (ArgumentError)

67
68
69
70
71
72
73
74
75
# File 'app/services/namespaces/in_product_marketing_emails_service.rb', line 67

def execute
  raise ArgumentError, "Track #{track} not defined" unless TRACKS.key?(track)

  groups_for_track.each_batch do |groups|
    groups.each do |group|
      send_email_for_group(group)
    end
  end
end