Class: Roadworker::Batch

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/roadworker/batch.rb

Defined Under Namespace

Classes: Create, Delete, Operation, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initialize(hosted_zone, dry_run:, logger:, health_checks:) ⇒ Batch

Returns a new instance of Batch.



7
8
9
10
11
12
13
14
# File 'lib/roadworker/batch.rb', line 7

def initialize(hosted_zone, dry_run:, logger:, health_checks:)
  @hosted_zone = hosted_zone
  @dry_run = dry_run
  @logger = logger
  @health_checks = health_checks

  @operations = []
end

Instance Attribute Details

#dry_runObject (readonly)

Returns the value of attribute dry_run.



17
18
19
# File 'lib/roadworker/batch.rb', line 17

def dry_run
  @dry_run
end

#health_checksObject (readonly)

Returns the value of attribute health_checks.



16
17
18
# File 'lib/roadworker/batch.rb', line 16

def health_checks
  @health_checks
end

#hosted_zoneObject (readonly)

Returns the value of attribute hosted_zone.



16
17
18
# File 'lib/roadworker/batch.rb', line 16

def hosted_zone
  @hosted_zone
end

#loggerObject (readonly)

Returns the value of attribute logger.



17
18
19
# File 'lib/roadworker/batch.rb', line 17

def logger
  @logger
end

#operationsObject (readonly)

Returns the value of attribute operations.



18
19
20
# File 'lib/roadworker/batch.rb', line 18

def operations
  @operations
end

Instance Method Details

#create(rrset) ⇒ Object

Parameters:

  • rrset (OpenStruct)

    Roadworker::DSL::ResourceRecordSet#result



21
22
23
# File 'lib/roadworker/batch.rb', line 21

def create(rrset)
  add_operation Create, rrset
end

#delete(rrset) ⇒ Object



31
32
33
# File 'lib/roadworker/batch.rb', line 31

def delete(rrset)
  add_operation Delete, rrset
end

#inspectObject



48
49
50
# File 'lib/roadworker/batch.rb', line 48

def inspect
  "#<#{self.class.name}: #{operations.size} operations>"
end

#request!(route53) ⇒ Boolean

Returns updated.

Parameters:

  • route53 (Aws::Route53::Client)

Returns:

  • (Boolean)

    updated



37
38
39
40
41
42
43
44
45
46
# File 'lib/roadworker/batch.rb', line 37

def request!(route53)
  sorted_operations = operations.sort_by(&:sort_key)

  batches = slice_operations(sorted_operations)
  batches.each_with_index do |batch, i|
    dispatch_batch!(route53, batch, i, batches.size)
  end

  sorted_operations.any? { |op| !op.changes.empty? }
end

#to_sObject



52
53
54
# File 'lib/roadworker/batch.rb', line 52

def to_s
  inspect
end

#update(rrset) ⇒ Object

Parameters:

  • rrset (OpenStruct)

    Roadworker::DSL::ResourceRecordSet#result



26
27
28
# File 'lib/roadworker/batch.rb', line 26

def update(rrset)
  add_operation Update, rrset
end