Class: Putpaws::Scheduler::ScheduleCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/putpaws/scheduler/schedule_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schedule_config) ⇒ ScheduleCommand

Returns a new instance of ScheduleCommand.



12
13
14
15
16
17
# File 'lib/putpaws/scheduler/schedule_command.rb', line 12

def initialize(schedule_config)
  @config = schedule_config
  @network = config.network
  @target = config.target
  @client = Aws::Scheduler::Client.new({region: config.region})
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/putpaws/scheduler/schedule_command.rb', line 9

def client
  @client
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/putpaws/scheduler/schedule_command.rb', line 10

def config
  @config
end

#networkObject (readonly)

Returns the value of attribute network.



10
11
12
# File 'lib/putpaws/scheduler/schedule_command.rb', line 10

def network
  @network
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/putpaws/scheduler/schedule_command.rb', line 10

def target
  @target
end

Class Method Details

.config(config) ⇒ Object



5
6
7
# File 'lib/putpaws/scheduler/schedule_command.rb', line 5

def self.config(config)
  new(**config.log_command_params)
end

Instance Method Details

#deploy!Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/putpaws/scheduler/schedule_command.rb', line 50

def deploy!
  # TODO: Use deep merge here
  args = generated_params.merge(config.args)

  begin
    res = client.get_schedule(name: config.name)
    client.update_schedule(args)
  rescue Aws::Scheduler::Errors::ResourceNotFoundException => e
    client.create_schedule(args)
  end
end

#generated_paramsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/putpaws/scheduler/schedule_command.rb', line 19

def generated_params
  {
    name: config.name,
    flexible_time_window: {mode: "OFF"},
    target: {
      arn: target.cluster,
      role_arn: target.scheduler_role,
      retry_policy: {maximum_retry_attempts: 0},
      input: {
        containerOverrides: [
          {
            name: target.container_name,
            command: config.command,
          }
        ]
      }.to_json,
      ecs_parameters: {
        launch_type: "FARGATE",
        network_configuration: {
          awsvpc_configuration: {
            subnets: network.subnets,
            security_groups: network.security_groups,
            assign_public_ip: network.assign_public_ip,
          }
        },
        task_definition_arn: target.task_definition,
        task_count: 1,          }
    }
  }
end