Module: Carson::Runtime::Govern

Included in:
Carson::Runtime
Defined in:
lib/carson/runtime/govern.rb

Instance Method Summary collapse

Instance Method Details

#govern!(dry_run: false, json_output: false, loop_seconds: nil) ⇒ Object

Portfolio-level entry point. Scans governed repos (or the current repo) and advances deliveries.



10
11
12
13
14
15
16
# File 'lib/carson/runtime/govern.rb', line 10

def govern!( dry_run: false, json_output: false, loop_seconds: nil )
	if loop_seconds
		govern_loop!( dry_run: dry_run, json_output: json_output, loop_seconds: loop_seconds )
	else
		govern_cycle!( dry_run: dry_run, json_output: json_output )
	end
end

#govern_cycle!(dry_run:, json_output:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/carson/runtime/govern.rb', line 18

def govern_cycle!( dry_run:, json_output: )
	print_header "Carson Govern"
	repositories = governed_repo_paths
	repositories = [ repository_record.path ] if repositories.empty?
	puts_line "governing #{repositories.length} repo#{plural_suffix( count: repositories.length )}"

	report = {
		cycle_at: Time.now.utc.iso8601,
		dry_run: dry_run,
		repositories: repositories.map { |path| govern_repo!( repo_path: path, dry_run: dry_run ) }
	}

	if json_output
		output.puts JSON.pretty_generate( report )
	else
		print_govern_summary( report: report )
	end

	EXIT_OK
rescue StandardError => exception
	puts_line "Govern did not complete: #{exception.message}"
	EXIT_ERROR
end

#govern_loop!(dry_run:, json_output:, loop_seconds:) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/carson/runtime/govern.rb', line 42

def govern_loop!( dry_run:, json_output:, loop_seconds: )
	cycle_count = 0
	loop do
		cycle_count += 1
		puts_line ""
		puts_line "cycle #{cycle_count} at #{Time.now.utc.strftime( '%Y-%m-%d %H:%M:%S UTC' )}"
		govern_cycle!( dry_run: dry_run, json_output: json_output )
		sleep loop_seconds
	end
rescue Interrupt
	puts_line "govern loop stopped after #{cycle_count} cycle#{plural_suffix( count: cycle_count )}"
	EXIT_OK
end