Module: Jets::Cfn::Builders::ParentBuilder::Stagger

Included in:
Jets::Cfn::Builders::ParentBuilder
Defined in:
lib/jets/cfn/builders/parent_builder/stagger.rb

Instance Method Summary collapse

Instance Method Details

#add_stagger(resource) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jets/cfn/builders/parent_builder/stagger.rb', line 3

def add_stagger(resource)
  batch_size = stagger_batch_size # shorter convenience variable
  return if !stagger_enabled || batch_size.nil? || batch_size == 0

  # initialize all here to keep logic together
  @previous_stacks ||= []
  @added_count ||= 0

  if @previous_stacks.size >= batch_size
    at_boundary = @added_count % batch_size == 0
    if at_boundary
      @left = @added_count - batch_size
      @right = @left + batch_size - 1
    end
    previous_stack_batch = @previous_stacks[@left..@right]
    resource.add_stagger_depends_on(previous_stack_batch)
  end

  @added_count += 1
  @previous_stacks << resource
end

#stagger_batch_sizeObject



25
26
27
# File 'lib/jets/cfn/builders/parent_builder/stagger.rb', line 25

def stagger_batch_size
  Jets.config.deploy.stagger.batch_size
end

#stagger_enabledObject

for spec-ing



30
31
32
# File 'lib/jets/cfn/builders/parent_builder/stagger.rb', line 30

def stagger_enabled
  Jets.config.deploy.stagger.enabled
end