Class: EcsDeployer::ScheduledTask::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ecs_deployer/scheduled_task/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(cluster, aws_options = {}) ⇒ EcsDeployer::ScheduledTask::Client

Parameters:

  • cluster (String)
  • aws_options (Hash) (defaults to: {})


9
10
11
12
13
# File 'lib/ecs_deployer/scheduled_task/client.rb', line 9

def initialize(cluster, aws_options = {})
  @cluster = cluster
  @cloud_watch_events = Aws::CloudWatchEvents::Client.new(aws_options)
  @aws_options = aws_options
end

Instance Method Details

#exist_rule?(rule) ⇒ Bool

Parameters:

  • rule (String)

Returns:

  • (Bool)


17
18
19
20
21
22
# File 'lib/ecs_deployer/scheduled_task/client.rb', line 17

def exist_rule?(rule)
  @cloud_watch_events.describe_rule(name: rule)
  true
rescue Aws::CloudWatchEvents::Errors::ResourceNotFoundException
  false
end

#target_builder(id) ⇒ EcsDeployer::ScheduledTask::Target

Parameters:

  • id (String)

Returns:



26
27
28
# File 'lib/ecs_deployer/scheduled_task/client.rb', line 26

def target_builder(id)
  EcsDeployer::ScheduledTask::Target.new(@cluster, id, @aws_options)
end

#update(rule, schedule_expression, targets = [], options = { description: nil }) ⇒ CloudWatchEvents::Types::PutRuleResponse

Parameters:

  • rule (String)
  • schedule_expression (String)
  • targets (Array) (defaults to: [])
  • options (Hash) (defaults to: { description: nil })

Returns:

  • (CloudWatchEvents::Types::PutRuleResponse)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ecs_deployer/scheduled_task/client.rb', line 35

def update(rule, schedule_expression, targets = [], options = { description: nil })
  response = @cloud_watch_events.put_rule(
    name: rule,
    schedule_expression: schedule_expression,
    state: 'ENABLED',
    description: options[:description]
  )
  @cloud_watch_events.put_targets(
    rule: rule,
    targets: targets
  )

  response
end