Class: Xronor::Generator::CloudWatchEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/xronor/generator/cloud_watch_events.rb

Class Method Summary collapse

Class Method Details

.generate(filename, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xronor/generator/cloud_watch_events.rb', line 5

def generate(filename, options)
  jobs = Xronor::Parser.parse(filename)
  function_arn = lambda.retrieve_function_arn(options[:function])

  current_jobs = cwe.list_jobs(options[:prefix])
  add_jobs, delete_jobs = compare_jobs(options[:prefix], current_jobs, jobs)

  added_rule_arns = add_jobs.map do |job|
    if options[:dry_run]
      puts "[DRYRUN] #{job.name} will be registered to CloudWatch Events"
    else
      arn = cwe.register_job(
        job,
        options[:prefix],
        options[:cluster],
        options[:task_definition],
        options[:container],
        function_arn,
      )
      puts "Registered #{arn}"
      arn
    end
  end

  if options[:dry_run]
  else
    dynamodb.sync_rule_arns(options[:table], added_rule_arns, [])
  end

  delete_jobs.each do |job|
    if options[:dry_run]
      puts "[DRYRUN] #{job} will be deregistered from CloudWatch Events"
    else
      cwe.deregister_job(job)
      puts "Deregistered #{job}"
    end
  end
end