Module: Jets::Job::Dsl::CloudwatchEvent

Defined in:
lib/jets/job/dsl/cloudwatch_event.rb

Instance Method Summary collapse

Instance Method Details

#add_descriptionsObject

Works with eager definitions



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 54

def add_descriptions
  numbered_resources = []
  n = 1
  @associated_resources.map do |associated|
    # definition = associated.definition
    # puts "associated #{associated.inspect}"
    # puts "definition #{definition.inspect}"

    # logical_id = definition.keys.first
    # attributes = definition.values.first

    logical_id = associated.logical_id
    attributes = associated.attributes

    attributes[:properties][:description] ||= "#{self.name} Event Rule #{n}"
    new_definition = { "#{logical_id}" => attributes }
    numbered_resources << Jets::Resource::Associated.new(new_definition)
    n += 1
  end
  @associated_resources = numbered_resources
end

#cron(expression, props = {}) ⇒ Object

Public: Creates CloudWatch Event Rule

expression - The cron expression.

Examples

cron("0 */12 * * ? *")
cron("0 */12 * * ? *", description: "Hard job")


25
26
27
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 25

def cron(expression, props={})
  schedule_job("cron(#{expression})", props)
end

#event_pattern(details = {}, props = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 37

def event_pattern(details={}, props={})
  with_fresh_properties(multiple_resources: false) do
    props = props.merge(event_pattern: details)
    associated_properties(props)
    resource(events_rule_definition) # add associated resource immediately
  end
  add_descriptions # useful: generic description in the Event Rule console
end

#events_rule(props = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 46

def events_rule(props={})
  with_fresh_properties(multiple_resources: false) do
    associated_properties(props)
    resource(events_rule_definition) # add associated resource immediately
  end
end

#events_rule_definitionObject



76
77
78
79
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 76

def events_rule_definition
  resource = Jets::Resource::Events::Rule.new(associated_properties)
  resource.definition # returns a definition to be added by associated_resources
end

#rate(expression, props = {}) ⇒ Object

Public: Creates CloudWatch Event Rule

expression - The rate expression.

Examples

rate("10 minutes")
rate("10 minutes", description: "Hard job")


12
13
14
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 12

def rate(expression, props={})
  schedule_job("rate(#{expression})", props)
end

#schedule_job(expression, props = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/jets/job/dsl/cloudwatch_event.rb', line 29

def schedule_job(expression, props={})
  with_fresh_properties(multiple_resources: false) do
    props = props.merge(schedule_expression: expression)
    associated_properties(props)
    resource(events_rule_definition) # add associated resource immediately
  end
end