Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10770 from alphagov/GOVUK_DATA_SYNC_PERIOD
Browse files Browse the repository at this point in the history
Expose GOVUK_DATA_SYNC_PERIOD ENV variable for govuk_app_config
  • Loading branch information
ChrisBAshton authored Oct 20, 2020
2 parents 6fa944d + 45fa8c2 commit 1a69ab2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
38 changes: 38 additions & 0 deletions modules/govuk/lib/puppet/parser/functions/data_sync_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Puppet::Parser::Functions
newfunction(:data_sync_times, :type => :rvalue, :doc => <<-EOS
Return information about the data sync times, depending on the argument passed
EOS
) do |args|
start_hour = 22
start_minute = 0
finish_hour = 8
finish_minute = 0
expected_args = 1

if args.size != expected_args
raise ArgumentError, "data_sync_times: Wrong number of arguments " +
"(given #{args.size}, expected #{expected_args})"
end

type = args[0]

case type
when 'time_range'
"#{start_hour}:#{start_minute}-#{finish_hour}:#{finish_minute}"
when 'start_time'
"#{start_hour}:#{start_minute}"
when 'start_hour'
start_hour
when 'start_minute'
start_minute
when 'finish_time'
"#{finish_hour}:#{finish_minute}"
when 'finish_hour'
finish_hour
when 'finish_minute'
finish_minute
else
raise ArgumentError, "data_sync_times: Unknown argument #{type}"
end
end
end
6 changes: 6 additions & 0 deletions modules/govuk/manifests/deploy/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
'GOVUK_CSP_REPORT_URI': value => $csp_report_uri;
}

if $::aws_migration and ($::aws_environment != 'production') {
govuk_envvar {
'GOVUK_DATA_SYNC_PERIOD': value => data_sync_times('time_range');
}
}

if $::aws_migration {
$app_domain_internal = hiera('app_domain_internal')

Expand Down
22 changes: 8 additions & 14 deletions modules/govuk_data_sync_in_progress/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
) {
$fact_path = '/etc/govuk/env.d/FACTER_data_sync_in_progress'

$start_hour = 22
$start_minute = 0

$finish_hour = 8
$finish_minute = 00

if !defined(File[$fact_path]) {
file { $fact_path:
ensure => present,
Expand All @@ -35,35 +29,35 @@
cron { 'data_sync_started':
command => "echo 'true' > ${fact_path}",
user => 'deploy',
hour => $start_hour,
minute => $start_minute,
hour => data_sync_times('start_hour'),
minute => data_sync_times('start_minute'),
}
}

if !defined(Cron['data_sync_finished']) {
cron { 'data_sync_finished':
command => "echo '' > ${$fact_path}",
user => 'deploy',
hour => $finish_hour,
minute => $finish_minute,
hour => data_sync_times('finish_hour'),
minute => data_sync_times('finish_minute'),
}
}

if $start_command {
cron { "data_sync_started_${title}":
command => $start_command,
user => 'deploy',
hour => $start_hour,
minute => $start_minute,
hour => data_sync_times('start_hour'),
minute => data_sync_times('start_minute'),
}
}

if $finish_command {
cron { "data_sync_finished_${title}":
command => $finish_command,
user => 'deploy',
hour => $finish_hour,
minute => $finish_minute,
hour => data_sync_times('finish_hour'),
minute => data_sync_times('finish_minute'),
}
}
}
5 changes: 2 additions & 3 deletions modules/monitoring/manifests/contacts.pp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@
$midday = '11:00'
$office_day_end = '16:30'
$midnight_day_end = '24:00'
# This should match up with the govuk_data_sync_in_progress class
$data_sync_start = '22:00'
$data_sync_end = '08:00'
$data_sync_start = data_sync_times('start_time')
$data_sync_end = data_sync_times('finish_time')

$all_day = "${midnight_day_start}-${midnight_day_end}"
$office_day = "${office_day_start}-${office_day_end}"
Expand Down

0 comments on commit 1a69ab2

Please sign in to comment.