Class: Kennel::Syncer
- Inherits:
-
Object
- Object
- Kennel::Syncer
- Defined in:
- lib/kennel/syncer.rb
Constant Summary collapse
- CACHE_FILE =
keep in sync with .travis.yml caching
"tmp/cache/details"
- TRACKING_FIELDS =
[:message, :description].freeze
- DELETE_ORDER =
dashboards references monitors + slos, slos reference monitors
["dashboard", "slo", "monitor"].freeze
Instance Method Summary collapse
- #confirm ⇒ Object
-
#initialize(api, expected, project: nil) ⇒ Syncer
constructor
A new instance of Syncer.
- #plan ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(api, expected, project: nil) ⇒ Syncer
Returns a new instance of Syncer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kennel/syncer.rb', line 8 def initialize(api, expected, project: nil) @api = api @project_filter = project @expected = expected if @project_filter original = @expected @expected = @expected.select { |e| e.project.kennel_id == @project_filter } if @expected.empty? possible = original.map { |e| e.project.kennel_id }.uniq.sort raise "#{@project_filter} does not match any projects, try any of these:\n#{possible.join("\n")}" end end @expected.each { |e| add_tracking_id e } calculate_diff prevent_irreversible_partial_updates end |
Instance Method Details
#confirm ⇒ Object
36 37 38 |
# File 'lib/kennel/syncer.rb', line 36 def confirm ENV["CI"] || !STDIN.tty? || Utils.ask("Execute Plan ?") unless noop? end |
#plan ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kennel/syncer.rb', line 25 def plan Kennel.out.puts "Plan:" if noop? Kennel.out.puts Utils.color(:green, "Nothing to do") else print_plan "Create", @create, :green print_plan "Update", @update, :yellow print_plan "Delete", @delete, :red end end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kennel/syncer.rb', line 40 def update each_resolved @create do |_, e| reply = @api.create e.class.api_resource, e.as_json id = reply.fetch(:id) populate_id_map [reply] # allow resolving ids we could previously no resolve Kennel.out.puts "Created #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(id)}" end each_resolved @update do |id, e| @api.update e.class.api_resource, id, e.as_json Kennel.out.puts "Updated #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(id)}" end @delete.each do |id, _, a| @api.delete a.fetch(:api_resource), id Kennel.out.puts "Deleted #{a.fetch(:api_resource)} #{tracking_id(a)} #{id}" end end |